Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2108d361 authored by Jason Monk's avatar Jason Monk
Browse files

Add default app prefs to app info

This makes them easier to discover and to know the state of them.

Bug: 27276982
Change-Id: I24a9d34d7e189b19df39cc0b9028b6412f76aa05
parent 91e2f89b
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -136,7 +136,8 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
                mPackageInfo = mPm.getPackageInfo(mAppEntry.info.packageName,
                        PackageManager.GET_DISABLED_COMPONENTS |
                        PackageManager.GET_UNINSTALLED_PACKAGES |
                        PackageManager.GET_SIGNATURES);
                        PackageManager.GET_SIGNATURES |
                        PackageManager.GET_PERMISSIONS);
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Exception when retrieving package:" + mAppEntry.info.packageName, e);
            }
+2 −1
Original line number Diff line number Diff line
@@ -43,7 +43,8 @@ public abstract class AppStateBaseBridge implements ApplicationsState.Callbacks
        // Running on the same background thread as the ApplicationsState lets
        // us run in the background and make sure they aren't doing updates at
        // the same time as us as well.
        mHandler = new BackgroundHandler(mAppState.getBackgroundLooper());
        mHandler = new BackgroundHandler(mAppState != null ? mAppState.getBackgroundLooper()
                : Looper.getMainLooper());
        mMainHandler = new MainHandler();
    }

+18 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Handler;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
@@ -172,4 +173,21 @@ public class DefaultBrowserPreference extends AppListPreference {
            mHandler.postDelayed(mUpdateRunnable, DELAY_UPDATE_BROWSER_MILLIS);
        }
    };

    public static boolean hasBrowserPreference(String pkg, Context context) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        intent.setData(Uri.parse("http:"));
        intent.setPackage(pkg);
        final List<ResolveInfo> resolveInfos =
                context.getPackageManager().queryIntentActivities(intent, 0);
        return resolveInfos != null && resolveInfos.size() != 0;
    }

    public static boolean isBrowserDefault(String pkg, Context context) {
        String defaultPackage = context.getPackageManager()
                .getDefaultBrowserPackageNameAsUser(UserHandle.myUserId());
        return defaultPackage != null && defaultPackage.equals(pkg);
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.applications;

import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -29,6 +30,7 @@ import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.AttributeSet;
import com.android.internal.telephony.SmsApplication;
import com.android.settings.AppListPreference;
import com.android.settings.SelfAvailablePreference;

@@ -146,4 +148,18 @@ public class DefaultEmergencyPreference extends AppListPreference
        return isCapable(context)
                && context.getPackageManager().resolveActivity(QUERY_INTENT, 0) != null;
    }

    public static boolean hasEmergencyPreference(String pkg, Context context) {
        Intent i = new Intent(QUERY_INTENT);
        i.setPackage(pkg);
        final List<ResolveInfo> resolveInfos =
                context.getPackageManager().queryIntentActivities(i, 0);
        return resolveInfos != null && resolveInfos.size() != 0;
    }

    public static boolean isEmergencyDefault(String pkg, Context context) {
        String defaultPackage = Settings.Secure.getString(context.getContentResolver(),
                Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION);
        return defaultPackage != null && defaultPackage.equals(pkg);
    }
}
+20 −0
Original line number Diff line number Diff line
@@ -114,4 +114,24 @@ public class DefaultHomePreference extends AppListPreference {
        }
        return false;
    }

    public static boolean hasHomePreference(String pkg, Context context) {
        ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
        PackageManager pm = context.getPackageManager();
        pm.getHomeActivities(homeActivities);
        for (int i = 0; i < homeActivities.size(); i++) {
            if (homeActivities.get(i).activityInfo.packageName.equals(pkg)) {
                return true;
            }
        }
        return false;
    }

    public static boolean isHomeDefault(String pkg, Context context) {
        ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
        PackageManager pm = context.getPackageManager();
        ComponentName def = pm.getHomeActivities(homeActivities);

        return def != null && def.getPackageName().equals(pkg);
    }
}
Loading