// Path: app/src/main/java/net/hyx/app/volumenotification/controller/NotificationServiceController.java
// public class NotificationServiceController {
// 
//     private final Context context;
//     private final SettingsModel settings;
// 
//     public NotificationServiceController(Context context) {
//         this.context = context;
//         settings = new SettingsModel(context);
//     }
// 
//     public static NotificationServiceController newInstance(Context context) {
//         return new NotificationServiceController(context);
//     }
// 
//     public void startService() {
//         NotificationBackgroundService.enqueueWork(context, new Intent(context, NotificationBackgroundService.class));
//     }
// 
//     public void checkEnableStartAtBoot() {
//         PackageManager pm = context.getPackageManager();
//         ComponentName receiver = new ComponentName(context, StartServiceReceiver.class);
// 
//         if (settings.startsAtBoot()) {
//             pm.setComponentEnabledSetting(receiver,
//                     PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
//                     PackageManager.DONT_KILL_APP);
//         } else {
//             pm.setComponentEnabledSetting(receiver,
//                     PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
//                     PackageManager.DONT_KILL_APP);
//         }
//     }
// 
//     public void checkStartNotificationService() {
//         if (settings.isEnabled()) {
//             if (settings.hasForegroundService()) {
//                 startForegroundService();
//             } else {
//                 stopForegroundService();
//             }
//             NotificationFactory factory = new NotificationFactory(context);
//             factory.startNotification();
//         } else {
//             stopForegroundService();
//             NotificationFactory factory = new NotificationFactory(context);
//             factory.cancelNotification();
//         }
//     }
// 
//     private void startForegroundService() {
//         ContextCompat.startForegroundService(context, new Intent(context, NotificationForegroundService.class));
//     }
// 
//     private void stopForegroundService() {
//         context.stopService(new Intent(context, NotificationForegroundService.class));
//     }
// 
// }
// 
// Path: app/src/main/java/net/hyx/app/volumenotification/controller/TileServiceController.java
// public class TileServiceController {
// 
//     private final Context context;
//     private final VolumeControlModel volumeControlModel;
// 
//     public TileServiceController(Context context) {
//         this.context = context;
//         volumeControlModel = new VolumeControlModel(context);
//     }
// 
//     public static TileServiceController newInstance(Context context) {
//         return new TileServiceController(context);
//     }
// 
//     public void requestListening() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//             requestListeningTiles();
//         }
//     }
// 
//     @TargetApi(Build.VERSION_CODES.N)
//     private void requestListeningTiles() {
//         String[] tileServices = {
//                 TileServiceMediaVolume.class.getName(),
//                 TileServiceCallVolume.class.getName(),
//                 TileServiceRingVolume.class.getName(),
//                 TileServiceAlarmVolume.class.getName(),
//                 TileServiceNotificationVolume.class.getName(),
//                 TileServiceSystemVolume.class.getName(),
//                 TileServiceDialVolume.class.getName(),
//                 TileServiceAccessibilityVolume.class.getName(),
//                 //TileServiceDefaultVolume.class.getName(),
//         };
//         for (String service : tileServices) {
//             TileService.requestListeningState(context, new ComponentName(context, service));
//         }
//     }
// 
//     @TargetApi(Build.VERSION_CODES.N)
//     public void updateTile(Tile tile, int streamType) {
//         VolumeControl item = volumeControlModel.getItemByType(streamType);
//         if (item == null) {
//             item = volumeControlModel.getDefaultControls().get(streamType);
//         }
//         tile.setIcon(Icon.createWithResource(context, volumeControlModel.getIconId(item.icon)));
//         tile.setLabel(item.label);
//         tile.setState(Tile.STATE_ACTIVE);
//         tile.updateTile();
//     }
// 
// }


import android.content.Context;
import android.content.Intent;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.core.app.JobIntentService;
import net.hyx.app.volumenotification.controller.NotificationServiceController;
import net.hyx.app.volumenotification.controller.TileServiceController;
/*
 * Copyright 2017 https://github.com/seht
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.hyx.app.volumenotification.service;

//import android.os.IBinder;
//import android.util.Log;



/**
 * @see {https://developer.android.com/reference/androidx/core/app/JobIntentService}
 */
public class NotificationBackgroundService extends JobIntentService {

    private static final int JOB_ID = 1000;
    
    public static void enqueueWork(Context context, Intent work) {
        JobIntentService.enqueueWork(context, NotificationBackgroundService.class, JOB_ID, work);
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    protected void onHandleWork(@NonNull Intent intent) {
        NotificationServiceController.newInstance(getApplicationContext()).checkStartNotificationService();
// Path: app/src/main/java/net/hyx/app/volumenotification/controller/NotificationServiceController.java
// public class NotificationServiceController {
// 
//     private final Context context;
//     private final SettingsModel settings;
// 
//     public NotificationServiceController(Context context) {
//         this.context = context;
//         settings = new SettingsModel(context);
//     }
// 
//     public static NotificationServiceController newInstance(Context context) {
//         return new NotificationServiceController(context);
//     }
// 
//     public void startService() {
//         NotificationBackgroundService.enqueueWork(context, new Intent(context, NotificationBackgroundService.class));
//     }
// 
//     public void checkEnableStartAtBoot() {
//         PackageManager pm = context.getPackageManager();
//         ComponentName receiver = new ComponentName(context, StartServiceReceiver.class);
// 
//         if (settings.startsAtBoot()) {
//             pm.setComponentEnabledSetting(receiver,
//                     PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
//                     PackageManager.DONT_KILL_APP);
//         } else {
//             pm.setComponentEnabledSetting(receiver,
//                     PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
//                     PackageManager.DONT_KILL_APP);
//         }
//     }
// 
//     public void checkStartNotificationService() {
//         if (settings.isEnabled()) {
//             if (settings.hasForegroundService()) {
//                 startForegroundService();
//             } else {
//                 stopForegroundService();
//             }
//             NotificationFactory factory = new NotificationFactory(context);
//             factory.startNotification();
//         } else {
//             stopForegroundService();
//             NotificationFactory factory = new NotificationFactory(context);
//             factory.cancelNotification();
//         }
//     }
// 
//     private void startForegroundService() {
//         ContextCompat.startForegroundService(context, new Intent(context, NotificationForegroundService.class));
//     }
// 
//     private void stopForegroundService() {
//         context.stopService(new Intent(context, NotificationForegroundService.class));
//     }
// 
// }
// 
// Path: app/src/main/java/net/hyx/app/volumenotification/controller/TileServiceController.java
// public class TileServiceController {
// 
//     private final Context context;
//     private final VolumeControlModel volumeControlModel;
// 
//     public TileServiceController(Context context) {
//         this.context = context;
//         volumeControlModel = new VolumeControlModel(context);
//     }
// 
//     public static TileServiceController newInstance(Context context) {
//         return new TileServiceController(context);
//     }
// 
//     public void requestListening() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//             requestListeningTiles();
//         }
//     }
// 
//     @TargetApi(Build.VERSION_CODES.N)
//     private void requestListeningTiles() {
//         String[] tileServices = {
//                 TileServiceMediaVolume.class.getName(),
//                 TileServiceCallVolume.class.getName(),
//                 TileServiceRingVolume.class.getName(),
//                 TileServiceAlarmVolume.class.getName(),
//                 TileServiceNotificationVolume.class.getName(),
//                 TileServiceSystemVolume.class.getName(),
//                 TileServiceDialVolume.class.getName(),
//                 TileServiceAccessibilityVolume.class.getName(),
//                 //TileServiceDefaultVolume.class.getName(),
//         };
//         for (String service : tileServices) {
//             TileService.requestListeningState(context, new ComponentName(context, service));
//         }
//     }
// 
//     @TargetApi(Build.VERSION_CODES.N)
//     public void updateTile(Tile tile, int streamType) {
//         VolumeControl item = volumeControlModel.getItemByType(streamType);
//         if (item == null) {
//             item = volumeControlModel.getDefaultControls().get(streamType);
//         }
//         tile.setIcon(Icon.createWithResource(context, volumeControlModel.getIconId(item.icon)));
//         tile.setLabel(item.label);
//         tile.setState(Tile.STATE_ACTIVE);
//         tile.updateTile();
//     }
// 
// }


// Path: app/src/main/java/net/hyx/app/volumenotification/service/NotificationBackgroundService.java
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.core.app.JobIntentService;
import net.hyx.app.volumenotification.controller.NotificationServiceController;
import net.hyx.app.volumenotification.controller.TileServiceController;

/*
 * Copyright 2017 https://github.com/seht
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.hyx.app.volumenotification.service;

//import android.os.IBinder;
//import android.util.Log;



/**
 * @see {https://developer.android.com/reference/androidx/core/app/JobIntentService}
 */
public class NotificationBackgroundService extends JobIntentService {

    private static final int JOB_ID = 1000;
    
    public static void enqueueWork(Context context, Intent work) {
        JobIntentService.enqueueWork(context, NotificationBackgroundService.class, JOB_ID, work);
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    protected void onHandleWork(@NonNull Intent intent) {
        NotificationServiceController.newInstance(getApplicationContext()).checkStartNotificationService();
        TileServiceController.newInstance(getApplicationContext()).requestListening();