Search in sources :

Example 66 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.

the class UserManagerService method readApplicationRestrictionsLP.

@VisibleForTesting
static Bundle readApplicationRestrictionsLP(AtomicFile restrictionsFile) {
    final Bundle restrictions = new Bundle();
    final ArrayList<String> values = new ArrayList<>();
    if (!restrictionsFile.getBaseFile().exists()) {
        return restrictions;
    }
    FileInputStream fis = null;
    try {
        fis = restrictionsFile.openRead();
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(fis, StandardCharsets.UTF_8.name());
        XmlUtils.nextElement(parser);
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            Slog.e(LOG_TAG, "Unable to read restrictions file " + restrictionsFile.getBaseFile());
            return restrictions;
        }
        while (parser.next() != XmlPullParser.END_DOCUMENT) {
            readEntry(restrictions, values, parser);
        }
    } catch (IOException | XmlPullParserException e) {
        Log.w(LOG_TAG, "Error parsing " + restrictionsFile.getBaseFile(), e);
    } finally {
        IoUtils.closeQuietly(fis);
    }
    return restrictions;
}
Also used : Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) ArrayList(java.util.ArrayList) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 67 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.

the class UserManagerService method writeApplicationRestrictionsLP.

@VisibleForTesting
static void writeApplicationRestrictionsLP(Bundle restrictions, AtomicFile restrictionsFile) {
    FileOutputStream fos = null;
    try {
        fos = restrictionsFile.startWrite();
        final BufferedOutputStream bos = new BufferedOutputStream(fos);
        final XmlSerializer serializer = new FastXmlSerializer();
        serializer.setOutput(bos, StandardCharsets.UTF_8.name());
        serializer.startDocument(null, true);
        serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        serializer.startTag(null, TAG_RESTRICTIONS);
        writeBundle(restrictions, serializer);
        serializer.endTag(null, TAG_RESTRICTIONS);
        serializer.endDocument();
        restrictionsFile.finishWrite(fos);
    } catch (Exception e) {
        restrictionsFile.failWrite(fos);
        Slog.e(LOG_TAG, "Error writing application restrictions list", e);
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) ErrnoException(android.system.ErrnoException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 68 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.

the class DevicePolicyManagerService method getProfileOwnerAdminLocked.

// Returns the active profile owner for this user or null if the current user has no
// profile owner.
@VisibleForTesting
ActiveAdmin getProfileOwnerAdminLocked(int userHandle) {
    ComponentName profileOwner = mOwners.getProfileOwnerComponent(userHandle);
    if (profileOwner == null) {
        return null;
    }
    DevicePolicyData policy = getUserData(userHandle);
    final int n = policy.mAdminList.size();
    for (int i = 0; i < n; i++) {
        ActiveAdmin admin = policy.mAdminList.get(i);
        if (profileOwner.equals(admin.info.getComponent())) {
            return admin;
        }
    }
    return null;
}
Also used : ComponentName(android.content.ComponentName) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 69 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.

the class DevicePolicyManagerService method isCallerDeviceOwner.

/**
     * Checks if the caller of the method is the device owner app.
     *
     * @param callerUid UID of the caller.
     * @return true if the caller is the device owner app
     */
@VisibleForTesting
boolean isCallerDeviceOwner(int callerUid) {
    synchronized (this) {
        if (!mOwners.hasDeviceOwner()) {
            return false;
        }
        if (UserHandle.getUserId(callerUid) != mOwners.getDeviceOwnerUserId()) {
            return false;
        }
        final String deviceOwnerPackageName = mOwners.getDeviceOwnerComponent().getPackageName();
        final String[] pkgs = mContext.getPackageManager().getPackagesForUid(callerUid);
        for (String pkg : pkgs) {
            if (deviceOwnerPackageName.equals(pkg)) {
                return true;
            }
        }
    }
    return false;
}
Also used : ParcelableString(com.android.internal.util.ParcelableString) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 70 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.

the class CarrierAppUtils method disableCarrierAppsUntilPrivileged.

// Must be public b/c framework unit tests can't access package-private methods.
@VisibleForTesting
public static void disableCarrierAppsUntilPrivileged(String callingPackage, IPackageManager packageManager, @Nullable TelephonyManager telephonyManager, ContentResolver contentResolver, int userId, String[] systemCarrierAppsDisabledUntilUsed, ArrayMap<String, List<String>> systemCarrierAssociatedAppsDisabledUntilUsed) {
    List<ApplicationInfo> candidates = getDefaultCarrierAppCandidatesHelper(packageManager, userId, systemCarrierAppsDisabledUntilUsed);
    if (candidates == null || candidates.isEmpty()) {
        return;
    }
    Map<String, List<ApplicationInfo>> associatedApps = getDefaultCarrierAssociatedAppsHelper(packageManager, userId, systemCarrierAssociatedAppsDisabledUntilUsed);
    List<String> enabledCarrierPackages = new ArrayList<>();
    boolean hasRunOnce = Settings.Secure.getIntForUser(contentResolver, Settings.Secure.CARRIER_APPS_HANDLED, 0, userId) == 1;
    try {
        for (ApplicationInfo ai : candidates) {
            String packageName = ai.packageName;
            boolean hasPrivileges = telephonyManager != null && telephonyManager.checkCarrierPrivilegesForPackageAnyPhone(packageName) == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
            if (hasPrivileges) {
                // updated we shouldn't touch it.
                if (!ai.isUpdatedSystemApp() && (ai.enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT || ai.enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
                    Slog.i(TAG, "Update state(" + packageName + "): ENABLED for user " + userId);
                    packageManager.setApplicationEnabledSetting(packageName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP, userId, callingPackage);
                }
                // Also enable any associated apps for this carrier app.
                List<ApplicationInfo> associatedAppList = associatedApps.get(packageName);
                if (associatedAppList != null) {
                    for (ApplicationInfo associatedApp : associatedAppList) {
                        if (associatedApp.enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT || associatedApp.enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
                            Slog.i(TAG, "Update associated state(" + associatedApp.packageName + "): ENABLED for user " + userId);
                            packageManager.setApplicationEnabledSetting(associatedApp.packageName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP, userId, callingPackage);
                        }
                    }
                }
                // Always re-grant default permissions to carrier apps w/ privileges.
                enabledCarrierPackages.add(ai.packageName);
            } else {
                // updated we shouldn't touch it.
                if (!ai.isUpdatedSystemApp() && ai.enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
                    Slog.i(TAG, "Update state(" + packageName + "): DISABLED_UNTIL_USED for user " + userId);
                    packageManager.setApplicationEnabledSetting(packageName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED, 0, userId, callingPackage);
                }
                // distinction between "default" and "enabled".
                if (!hasRunOnce) {
                    List<ApplicationInfo> associatedAppList = associatedApps.get(packageName);
                    if (associatedAppList != null) {
                        for (ApplicationInfo associatedApp : associatedAppList) {
                            if (associatedApp.enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
                                Slog.i(TAG, "Update associated state(" + associatedApp.packageName + "): DISABLED_UNTIL_USED for user " + userId);
                                packageManager.setApplicationEnabledSetting(associatedApp.packageName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED, 0, userId, callingPackage);
                            }
                        }
                    }
                }
            }
        }
        // Mark the execution so we do not disable apps again.
        if (!hasRunOnce) {
            Settings.Secure.putIntForUser(contentResolver, Settings.Secure.CARRIER_APPS_HANDLED, 1, userId);
        }
        if (!enabledCarrierPackages.isEmpty()) {
            // Since we enabled at least one app, ensure we grant default permissions to those
            // apps.
            String[] packageNames = new String[enabledCarrierPackages.size()];
            enabledCarrierPackages.toArray(packageNames);
            packageManager.grantDefaultPermissionsToEnabledCarrierApps(packageNames, userId);
        }
    } catch (RemoteException e) {
        Slog.w(TAG, "Could not reach PackageManager", e);
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RemoteException(android.os.RemoteException) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.android.internal.annotations.VisibleForTesting)141 ArrayList (java.util.ArrayList)39 IOException (java.io.IOException)26 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)18 ComponentName (android.content.ComponentName)15 File (java.io.File)14 RemoteException (android.os.RemoteException)13 ArraySet (android.util.ArraySet)10 AtomicFile (android.util.AtomicFile)10 FileInputStream (java.io.FileInputStream)10 Locale (java.util.Locale)10 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)9 FileNotFoundException (java.io.FileNotFoundException)9 Notification (android.app.Notification)6 ErrnoException (android.system.ErrnoException)6 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)6 FileOutputStream (java.io.FileOutputStream)6 XmlSerializer (org.xmlpull.v1.XmlSerializer)6 ITransientNotification (android.app.ITransientNotification)5 UserInfo (android.content.pm.UserInfo)5