/** * Performs dexopt on all code paths and libraries of the specified package for specified * instruction sets. * * <p>Calls to {@link com.android.server.pm.Installer#dexopt} are synchronized on {@link * PackageManagerService#mInstallLock}. */ int performDexOpt( PackageParser.Package pkg, String[] instructionSets, boolean forceDex, boolean defer, boolean inclDependencies) { ArraySet<String> done; if (inclDependencies && (pkg.usesLibraries != null || pkg.usesOptionalLibraries != null)) { done = new ArraySet<String>(); done.add(pkg.packageName); } else { done = null; } synchronized (mPackageManagerService.mInstallLock) { final boolean useLock = mSystemReady; if (useLock) { mDexoptWakeLock.setWorkSource(new WorkSource(pkg.applicationInfo.uid)); mDexoptWakeLock.acquire(); } try { return performDexOptLI(pkg, instructionSets, forceDex, defer, done); } finally { if (useLock) { mDexoptWakeLock.release(); } } } }
public void readFromXml(XmlPullParser parser) throws XmlPullParserException, IOException { mPackageName = getStringFromXml(parser, ATTR_PACKAGE_NAME, null); if (mPackageName == null) { Log.e(TAG, "Package name cannot be null!"); } int status = getIntFromXml(parser, ATTR_STATUS, -1); if (status == -1) { Log.e(TAG, "Unknown status value: " + status); } mMainStatus = status; int outerDepth = parser.getDepth(); int type; while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { continue; } String tagName = parser.getName(); if (tagName.equals(TAG_DOMAIN)) { String name = getStringFromXml(parser, ATTR_DOMAIN_NAME, null); if (!TextUtils.isEmpty(name)) { mDomains.add(name); } } else { Log.w(TAG, "Unknown tag parsing IntentFilter: " + tagName); } XmlUtils.skipCurrentTag(parser); } }
private ArraySet<Long> getPrimaryCalendars() { final long start = System.currentTimeMillis(); final ArraySet<Long> rt = new ArraySet<>(); final String primary = "\"primary\""; final String[] projection = { Calendars._ID, "(" + Calendars.ACCOUNT_NAME + "=" + Calendars.OWNER_ACCOUNT + ") AS " + primary }; final String selection = primary + " = 1"; Cursor cursor = null; try { cursor = mUserContext .getContentResolver() .query(Calendars.CONTENT_URI, projection, selection, null, null); while (cursor != null && cursor.moveToNext()) { rt.add(cursor.getLong(0)); } } finally { if (cursor != null) { cursor.close(); } } if (DEBUG) Log.d(TAG, "getPrimaryCalendars took " + (System.currentTimeMillis() - start)); return rt; }
public static ArraySet<String> getIconBlacklist(String blackListStr) { ArraySet<String> ret = new ArraySet<String>(); if (blackListStr != null) { String[] blacklist = blackListStr.split(","); for (String slot : blacklist) { if (!TextUtils.isEmpty(slot)) { ret.add(slot); } } } return ret; }
public void testOverridePins() throws Exception { // Use a bad pin + granting the system CA store the ability to override pins. ArrayList<CertificatesEntryRef> systemSource = new ArrayList<CertificatesEntryRef>(); systemSource.add(new CertificatesEntryRef(new SystemCertificateSource(), true)); ArraySet<Pin> pins = new ArraySet<Pin>(); pins.add(new Pin("SHA-256", new byte[0])); NetworkSecurityConfig domain = new NetworkSecurityConfig(true, false, new PinSet(pins, Long.MAX_VALUE), systemSource); ArraySet<Pair<Domain, NetworkSecurityConfig>> domainMap = new ArraySet<Pair<Domain, NetworkSecurityConfig>>(); domainMap.add(new Pair<Domain, NetworkSecurityConfig>(new Domain("android.com", true), domain)); SSLContext context = getSSLContext(new TestConfigSource(domainMap, getEmptyConfig())); assertConnectionSucceeds(context, "android.com", 443); }
public void testGoodPin() throws Exception { ArrayList<CertificatesEntryRef> systemSource = new ArrayList<CertificatesEntryRef>(); systemSource.add(new CertificatesEntryRef(new SystemCertificateSource(), false)); ArraySet<Pin> pins = new ArraySet<Pin>(); pins.add(new Pin("SHA-256", G2_SPKI_SHA256)); NetworkSecurityConfig domain = new NetworkSecurityConfig(true, false, new PinSet(pins, Long.MAX_VALUE), systemSource); ArraySet<Pair<Domain, NetworkSecurityConfig>> domainMap = new ArraySet<Pair<Domain, NetworkSecurityConfig>>(); domainMap.add(new Pair<Domain, NetworkSecurityConfig>(new Domain("android.com", true), domain)); SSLContext context = getSSLContext(new TestConfigSource(domainMap, getEmptyConfig())); assertConnectionSucceeds(context, "android.com", 443); assertConnectionSucceeds(context, "developer.android.com", 443); }
/** Returns the list of supported refresh rates in the default mode. */ public float[] getDefaultRefreshRates() { Display.Mode[] modes = supportedModes; ArraySet<Float> rates = new ArraySet<>(); Display.Mode defaultMode = getDefaultMode(); for (int i = 0; i < modes.length; i++) { Display.Mode mode = modes[i]; if (mode.getPhysicalWidth() == defaultMode.getPhysicalWidth() && mode.getPhysicalHeight() == defaultMode.getPhysicalHeight()) { rates.add(mode.getRefreshRate()); } } float[] result = new float[rates.size()]; int i = 0; for (Float rate : rates) { result[i++] = rate; } return result; }
void stopReportingCrashesLocked(ProcessRecord proc) { if (mAppsNotReportingCrashes == null) { mAppsNotReportingCrashes = new ArraySet<>(); } mAppsNotReportingCrashes.add(proc.info.packageName); }
public void addSocket(SocketClient client) { list.add(client); }
/** * Called whenever packages change, the user switches, or the secure setting is altered. (For * example in response to USER_SWITCHED in our broadcast receiver) */ private void rebindServices() { if (DEBUG) Slog.d(TAG, "rebindServices"); final int[] userIds = mUserProfiles.getCurrentProfileIds(); final int nUserIds = userIds.length; final SparseArray<String> flat = new SparseArray<String>(); for (int i = 0; i < nUserIds; ++i) { flat.put( userIds[i], Settings.Secure.getStringForUser( mContext.getContentResolver(), mConfig.secureSettingName, userIds[i])); } ArrayList<ManagedServiceInfo> toRemove = new ArrayList<ManagedServiceInfo>(); final SparseArray<ArrayList<ComponentName>> toAdd = new SparseArray<ArrayList<ComponentName>>(); synchronized (mMutex) { // Unbind automatically bound services, retain system services. for (ManagedServiceInfo service : mServices) { if (!service.isSystem) { toRemove.add(service); } } final ArraySet<ComponentName> newEnabled = new ArraySet<ComponentName>(); final ArraySet<String> newPackages = new ArraySet<String>(); for (int i = 0; i < nUserIds; ++i) { final ArrayList<ComponentName> add = new ArrayList<ComponentName>(); toAdd.put(userIds[i], add); // decode the list of components String toDecode = flat.get(userIds[i]); if (toDecode != null) { String[] components = toDecode.split(ENABLED_SERVICES_SEPARATOR); for (int j = 0; j < components.length; j++) { final ComponentName component = ComponentName.unflattenFromString(components[j]); if (component != null) { newEnabled.add(component); add.add(component); newPackages.add(component.getPackageName()); } } } } mEnabledServicesForCurrentProfiles = newEnabled; mEnabledServicesPackageNames = newPackages; } for (ManagedServiceInfo info : toRemove) { final ComponentName component = info.component; final int oldUser = info.userid; Slog.v(TAG, "disabling " + getCaption() + " for user " + oldUser + ": " + component); unregisterService(component, info.userid); } for (int i = 0; i < nUserIds; ++i) { final ArrayList<ComponentName> add = toAdd.get(userIds[i]); final int N = add.size(); for (int j = 0; j < N; j++) { final ComponentName component = add.get(j); Slog.v(TAG, "enabling " + getCaption() + " for user " + userIds[i] + ": " + component); registerService(component, userIds[i]); } } mLastSeenProfileIds = mUserProfiles.getCurrentProfileIds(); }
@Override public void startTransition( LayoutTransition transition, ViewGroup container, View view, int transitionType) { mTransitioningViews.add(view); updateTransitioning(); }
private int performDexOptLI( PackageParser.Package pkg, String[] targetInstructionSets, boolean forceDex, boolean defer, ArraySet<String> done) { final String[] instructionSets = targetInstructionSets != null ? targetInstructionSets : getAppDexInstructionSets(pkg.applicationInfo); if (done != null) { done.add(pkg.packageName); if (pkg.usesLibraries != null) { performDexOptLibsLI(pkg.usesLibraries, instructionSets, forceDex, defer, done); } if (pkg.usesOptionalLibraries != null) { performDexOptLibsLI(pkg.usesOptionalLibraries, instructionSets, forceDex, defer, done); } } if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) == 0) { return DEX_OPT_SKIPPED; } final boolean vmSafeMode = (pkg.applicationInfo.flags & ApplicationInfo.FLAG_VM_SAFE_MODE) != 0; final boolean debuggable = (pkg.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; final List<String> paths = pkg.getAllCodePathsExcludingResourceOnly(); boolean performedDexOpt = false; // There are three basic cases here: // 1.) we need to dexopt, either because we are forced or it is needed // 2.) we are deferring a needed dexopt // 3.) we are skipping an unneeded dexopt final String[] dexCodeInstructionSets = getDexCodeInstructionSets(instructionSets); for (String dexCodeInstructionSet : dexCodeInstructionSets) { if (!forceDex && pkg.mDexOptPerformed.contains(dexCodeInstructionSet)) { continue; } for (String path : paths) { final int dexoptNeeded; if (forceDex) { dexoptNeeded = DexFile.DEX2OAT_NEEDED; } else { try { dexoptNeeded = DexFile.getDexOptNeeded(path, pkg.packageName, dexCodeInstructionSet, defer); } catch (IOException ioe) { Slog.w(TAG, "IOException reading apk: " + path, ioe); return DEX_OPT_FAILED; } } if (!forceDex && defer && dexoptNeeded != DexFile.NO_DEXOPT_NEEDED) { // We're deciding to defer a needed dexopt. Don't bother dexopting for other // paths and instruction sets. We'll deal with them all together when we process // our list of deferred dexopts. addPackageForDeferredDexopt(pkg); return DEX_OPT_DEFERRED; } if (dexoptNeeded != DexFile.NO_DEXOPT_NEEDED) { final String dexoptType; String oatDir = null; if (dexoptNeeded == DexFile.DEX2OAT_NEEDED) { dexoptType = "dex2oat"; try { oatDir = createOatDirIfSupported(pkg, dexCodeInstructionSet); } catch (IOException ioe) { Slog.w(TAG, "Unable to create oatDir for package: " + pkg.packageName); return DEX_OPT_FAILED; } } else if (dexoptNeeded == DexFile.PATCHOAT_NEEDED) { dexoptType = "patchoat"; } else if (dexoptNeeded == DexFile.SELF_PATCHOAT_NEEDED) { dexoptType = "self patchoat"; } else { throw new IllegalStateException("Invalid dexopt needed: " + dexoptNeeded); } Log.i( TAG, "Running dexopt (" + dexoptType + ") on: " + path + " pkg=" + pkg.applicationInfo.packageName + " isa=" + dexCodeInstructionSet + " vmSafeMode=" + vmSafeMode + " debuggable=" + debuggable + " oatDir = " + oatDir); final int sharedGid = UserHandle.getSharedAppGid(pkg.applicationInfo.uid); final int ret = mPackageManagerService.mInstaller.dexopt( path, sharedGid, !pkg.isForwardLocked(), pkg.packageName, dexCodeInstructionSet, dexoptNeeded, vmSafeMode, debuggable, oatDir); // Dex2oat might fail due to compiler / verifier errors. We soldier on // regardless, and attempt to interpret the app as a safety net. if (ret == 0) { performedDexOpt = true; } } } // At this point we haven't failed dexopt and we haven't deferred dexopt. We must // either have either succeeded dexopt, or have had getDexOptNeeded tell us // it isn't required. We therefore mark that this package doesn't need dexopt unless // it's forced. performedDexOpt will tell us whether we performed dex-opt or skipped // it. pkg.mDexOptPerformed.add(dexCodeInstructionSet); } // If we've gotten here, we're sure that no error occurred and that we haven't // deferred dex-opt. We've either dex-opted one more paths or instruction sets or // we've skipped all of them because they are up to date. In both cases this // package doesn't need dexopt any longer. return performedDexOpt ? DEX_OPT_PERFORMED : DEX_OPT_SKIPPED; }
public void addPackageForDeferredDexopt(PackageParser.Package pkg) { if (mDeferredDexOpt == null) { mDeferredDexOpt = new ArraySet<>(); } mDeferredDexOpt.add(pkg); }