// Path: application/src/open/java/com/projectsexception/myapplist/app/MyAppListApplication.java
// public class MyAppListApplication extends Application {
// 
//     public static final String LOG_TAG = "MyAppList";
//     public static final int LOG_LEVEL = BuildConfig.DEBUG ? Log.DEBUG : Log.INFO;
// 
//     public void analyticsSetScreenName(String screenName) {
// 
//     }
// 
//     public void analyticsSend() {
// 
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         CustomLog.initLog(LOG_TAG, LOG_LEVEL);
//     }
// }
// 
// Path: application/src/main/java/com/projectsexception/myapplist/work/SaveListService.java
// public class SaveListService extends IntentService {
// 
//     private static final String TAG = "SaveListService";
//     private static final String SERVICE_NAME = TAG;
// 
//     public SaveListService() {
//         super(SERVICE_NAME);
//     }
// 
//     @Override
//     protected void onHandleIntent(Intent intent) {
//         CustomLog.getInstance().info(TAG, "Running service");
//         // Filename
//         String fileName = getString(R.string.backup_filename);
//         // Get app list from system
//         List<AppInfo> list = AppUtil.loadAppInfoList(getPackageManager(), true);
//         File file = FileUtil.loadFile(this, fileName);
//         if (file != null && file.exists()) {
//             SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
//             boolean uninstalledApps = prefs.getBoolean(MyAppListPreferenceActivity.KEY_BACKUP_UNINSTALLED_APPS, false);
//             if (uninstalledApps) {
//                 // Get app list from backup file
//                 AppXMLHandler xmlHandler = new AppXMLHandler();
//                 try {
//                     ParserUtil.launchParser(file, xmlHandler);
//                     ArrayList<AppInfo> appInfoList = xmlHandler.getAppInfoList();
//                     if (appInfoList != null && !appInfoList.isEmpty()) {
//                         Set<String> packages = new HashSet<String>();
//                         for (AppInfo appInfo : list) {
//                             packages.add(appInfo.getPackageName());
//                         }
//                         for (AppInfo appInfo : appInfoList) {
//                             if (!packages.contains(appInfo.getPackageName())) {
//                                 list.add(appInfo);
//                             }
//                         }
//                     }
//                 } catch (ParserException e) {
//                     CustomLog.getInstance().error(TAG, e);
//                 }
//             }
//         }
//         // Remove ignored apps
//         MyAppListDbHelper dbHelper = new MyAppListDbHelper(this);
//         List<String> packages = dbHelper.getPackages();
//         for (Iterator<AppInfo> it = list.iterator(); it.hasNext();) {
//             if (packages.contains(it.next().getPackageName())) {
//                 it.remove();
//             }
//         }
//         // Create file
//         FileUtil.writeFile(this, list, fileName);
//         // Exit
//         dbHelper.close();
//     }
//     
//     public static void updateService(Context ctx) {
//         setService(ctx, true);
//     }
//     
//     public static void cancelService(Context ctx) {
//         setService(ctx, false);
//     }
//     
//     private static void setService(Context ctx, boolean enable) {
//         AlarmManager alarm = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
//         Intent intent = new Intent(ctx, SaveListService.class);
//         PendingIntent pintent = PendingIntent.getService(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
//         if (enable) {
//             long time = System.currentTimeMillis() + (1000 * 60 * 15);
//             alarm.set(AlarmManager.RTC, time, pintent);
//         } else {
//             alarm.cancel(pintent);
//         }
//     }
// 
// }


import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import com.projectsexception.myapplist.app.MyAppListApplication;
import com.projectsexception.myapplist.work.SaveListService;
import com.projectsexception.util.CustomLog;
package com.projectsexception.myapplist.util;



public class BackupReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
// Path: application/src/open/java/com/projectsexception/myapplist/app/MyAppListApplication.java
// public class MyAppListApplication extends Application {
// 
//     public static final String LOG_TAG = "MyAppList";
//     public static final int LOG_LEVEL = BuildConfig.DEBUG ? Log.DEBUG : Log.INFO;
// 
//     public void analyticsSetScreenName(String screenName) {
// 
//     }
// 
//     public void analyticsSend() {
// 
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         CustomLog.initLog(LOG_TAG, LOG_LEVEL);
//     }
// }
// 
// Path: application/src/main/java/com/projectsexception/myapplist/work/SaveListService.java
// public class SaveListService extends IntentService {
// 
//     private static final String TAG = "SaveListService";
//     private static final String SERVICE_NAME = TAG;
// 
//     public SaveListService() {
//         super(SERVICE_NAME);
//     }
// 
//     @Override
//     protected void onHandleIntent(Intent intent) {
//         CustomLog.getInstance().info(TAG, "Running service");
//         // Filename
//         String fileName = getString(R.string.backup_filename);
//         // Get app list from system
//         List<AppInfo> list = AppUtil.loadAppInfoList(getPackageManager(), true);
//         File file = FileUtil.loadFile(this, fileName);
//         if (file != null && file.exists()) {
//             SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
//             boolean uninstalledApps = prefs.getBoolean(MyAppListPreferenceActivity.KEY_BACKUP_UNINSTALLED_APPS, false);
//             if (uninstalledApps) {
//                 // Get app list from backup file
//                 AppXMLHandler xmlHandler = new AppXMLHandler();
//                 try {
//                     ParserUtil.launchParser(file, xmlHandler);
//                     ArrayList<AppInfo> appInfoList = xmlHandler.getAppInfoList();
//                     if (appInfoList != null && !appInfoList.isEmpty()) {
//                         Set<String> packages = new HashSet<String>();
//                         for (AppInfo appInfo : list) {
//                             packages.add(appInfo.getPackageName());
//                         }
//                         for (AppInfo appInfo : appInfoList) {
//                             if (!packages.contains(appInfo.getPackageName())) {
//                                 list.add(appInfo);
//                             }
//                         }
//                     }
//                 } catch (ParserException e) {
//                     CustomLog.getInstance().error(TAG, e);
//                 }
//             }
//         }
//         // Remove ignored apps
//         MyAppListDbHelper dbHelper = new MyAppListDbHelper(this);
//         List<String> packages = dbHelper.getPackages();
//         for (Iterator<AppInfo> it = list.iterator(); it.hasNext();) {
//             if (packages.contains(it.next().getPackageName())) {
//                 it.remove();
//             }
//         }
//         // Create file
//         FileUtil.writeFile(this, list, fileName);
//         // Exit
//         dbHelper.close();
//     }
//     
//     public static void updateService(Context ctx) {
//         setService(ctx, true);
//     }
//     
//     public static void cancelService(Context ctx) {
//         setService(ctx, false);
//     }
//     
//     private static void setService(Context ctx, boolean enable) {
//         AlarmManager alarm = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
//         Intent intent = new Intent(ctx, SaveListService.class);
//         PendingIntent pintent = PendingIntent.getService(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
//         if (enable) {
//             long time = System.currentTimeMillis() + (1000 * 60 * 15);
//             alarm.set(AlarmManager.RTC, time, pintent);
//         } else {
//             alarm.cancel(pintent);
//         }
//     }
// 
// }


// Path: application/src/main/java/com/projectsexception/myapplist/util/BackupReceiver.java
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import com.projectsexception.myapplist.app.MyAppListApplication;
import com.projectsexception.myapplist.work.SaveListService;
import com.projectsexception.util.CustomLog;

package com.projectsexception.myapplist.util;



public class BackupReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        CustomLog.initLog(MyAppListApplication.LOG_TAG, MyAppListApplication.LOG_LEVEL);