OSDN Git Service

Don't show recent apps dialog if installed as system app
authorBraden Farmer <farmerbb@gmail.com>
Wed, 21 Dec 2016 03:13:47 +0000 (20:13 -0700)
committerBraden Farmer <farmerbb@gmail.com>
Wed, 21 Dec 2016 03:13:47 +0000 (20:13 -0700)
app/src/main/java/com/farmerbb/taskbar/MainActivity.java

index 80e1267..43ebc30 100644 (file)
@@ -171,7 +171,7 @@ public class MainActivity extends AppCompatActivity {
                             boolean firstRun = pref.getBoolean("first_run", true);
                             startTaskbarService();
 
-                            if(firstRun && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+                            if(firstRun && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !isSystemApp()) {
                                 ApplicationInfo applicationInfo = null;
                                 try {
                                     applicationInfo = getPackageManager().getApplicationInfo(BuildConfig.APPLICATION_ID, 0);
@@ -402,4 +402,14 @@ public class MainActivity extends AppCompatActivity {
 
         super.onSaveInstanceState(outState);
     }
+
+    private boolean isSystemApp() {
+        try {
+            ApplicationInfo info = getPackageManager().getApplicationInfo(BuildConfig.APPLICATION_ID, 0);
+            int mask = ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
+            return (info.flags & mask) != 0;
+        } catch (PackageManager.NameNotFoundException e) {
+            return false;
+        }
+    }
 }
\ No newline at end of file