Search in sources :

Example 41 with LogPrinter

use of android.util.LogPrinter in project platform_frameworks_base by android.

the class Settings method applyDefaultPreferredActivityLPw.

private void applyDefaultPreferredActivityLPw(PackageManagerService service, IntentFilter tmpPa, ComponentName cn, int userId) {
    // preferred activity entry.
    if (PackageManagerService.DEBUG_PREFERRED) {
        Log.d(TAG, "Processing preferred:");
        tmpPa.dump(new LogPrinter(Log.DEBUG, TAG), "  ");
    }
    Intent intent = new Intent();
    int flags = PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
    intent.setAction(tmpPa.getAction(0));
    for (int i = 0; i < tmpPa.countCategories(); i++) {
        String cat = tmpPa.getCategory(i);
        if (cat.equals(Intent.CATEGORY_DEFAULT)) {
            flags |= MATCH_DEFAULT_ONLY;
        } else {
            intent.addCategory(cat);
        }
    }
    boolean doNonData = true;
    boolean hasSchemes = false;
    for (int ischeme = 0; ischeme < tmpPa.countDataSchemes(); ischeme++) {
        boolean doScheme = true;
        String scheme = tmpPa.getDataScheme(ischeme);
        if (scheme != null && !scheme.isEmpty()) {
            hasSchemes = true;
        }
        for (int issp = 0; issp < tmpPa.countDataSchemeSpecificParts(); issp++) {
            Uri.Builder builder = new Uri.Builder();
            builder.scheme(scheme);
            PatternMatcher ssp = tmpPa.getDataSchemeSpecificPart(issp);
            builder.opaquePart(ssp.getPath());
            Intent finalIntent = new Intent(intent);
            finalIntent.setData(builder.build());
            applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, ssp, null, null, userId);
            doScheme = false;
        }
        for (int iauth = 0; iauth < tmpPa.countDataAuthorities(); iauth++) {
            boolean doAuth = true;
            IntentFilter.AuthorityEntry auth = tmpPa.getDataAuthority(iauth);
            for (int ipath = 0; ipath < tmpPa.countDataPaths(); ipath++) {
                Uri.Builder builder = new Uri.Builder();
                builder.scheme(scheme);
                if (auth.getHost() != null) {
                    builder.authority(auth.getHost());
                }
                PatternMatcher path = tmpPa.getDataPath(ipath);
                builder.path(path.getPath());
                Intent finalIntent = new Intent(intent);
                finalIntent.setData(builder.build());
                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, auth, path, userId);
                doAuth = doScheme = false;
            }
            if (doAuth) {
                Uri.Builder builder = new Uri.Builder();
                builder.scheme(scheme);
                if (auth.getHost() != null) {
                    builder.authority(auth.getHost());
                }
                Intent finalIntent = new Intent(intent);
                finalIntent.setData(builder.build());
                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, auth, null, userId);
                doScheme = false;
            }
        }
        if (doScheme) {
            Uri.Builder builder = new Uri.Builder();
            builder.scheme(scheme);
            Intent finalIntent = new Intent(intent);
            finalIntent.setData(builder.build());
            applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, null, null, userId);
        }
        doNonData = false;
    }
    for (int idata = 0; idata < tmpPa.countDataTypes(); idata++) {
        String mimeType = tmpPa.getDataType(idata);
        if (hasSchemes) {
            Uri.Builder builder = new Uri.Builder();
            for (int ischeme = 0; ischeme < tmpPa.countDataSchemes(); ischeme++) {
                String scheme = tmpPa.getDataScheme(ischeme);
                if (scheme != null && !scheme.isEmpty()) {
                    Intent finalIntent = new Intent(intent);
                    builder.scheme(scheme);
                    finalIntent.setDataAndType(builder.build(), mimeType);
                    applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, null, null, userId);
                }
            }
        } else {
            Intent finalIntent = new Intent(intent);
            finalIntent.setType(mimeType);
            applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, null, null, null, null, userId);
        }
        doNonData = false;
    }
    if (doNonData) {
        applyDefaultPreferredActivityLPw(service, intent, flags, cn, null, null, null, null, userId);
    }
}
Also used : IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) Uri(android.net.Uri) PatternMatcher(android.os.PatternMatcher) LogPrinter(android.util.LogPrinter)

Example 42 with LogPrinter

use of android.util.LogPrinter in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerService method replacePreferredActivity.

@Override
public void replacePreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity, int userId) {
    if (filter.countActions() != 1) {
        throw new IllegalArgumentException("replacePreferredActivity expects filter to have only 1 action.");
    }
    if (filter.countDataAuthorities() != 0 || filter.countDataPaths() != 0 || filter.countDataSchemes() > 1 || filter.countDataTypes() != 0) {
        throw new IllegalArgumentException("replacePreferredActivity expects filter to have no data authorities, " + "paths, or types; and at most one scheme.");
    }
    final int callingUid = Binder.getCallingUid();
    enforceCrossUserPermission(callingUid, userId, true, /* requireFullPermission */
    false, /* checkShell */
    "replace preferred activity");
    synchronized (mPackages) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS) != PackageManager.PERMISSION_GRANTED) {
            if (getUidTargetSdkVersionLockedLPr(callingUid) < Build.VERSION_CODES.FROYO) {
                Slog.w(TAG, "Ignoring replacePreferredActivity() from uid " + Binder.getCallingUid());
                return;
            }
            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
        }
        PreferredIntentResolver pir = mSettings.mPreferredActivities.get(userId);
        if (pir != null) {
            // Get all of the existing entries that exactly match this filter.
            ArrayList<PreferredActivity> existing = pir.findFilters(filter);
            if (existing != null && existing.size() == 1) {
                PreferredActivity cur = existing.get(0);
                if (DEBUG_PREFERRED) {
                    Slog.i(TAG, "Checking replace of preferred:");
                    filter.dump(new LogPrinter(Log.INFO, TAG), "  ");
                    if (!cur.mPref.mAlways) {
                        Slog.i(TAG, "  -- CUR; not mAlways!");
                    } else {
                        Slog.i(TAG, "  -- CUR: mMatch=" + cur.mPref.mMatch);
                        Slog.i(TAG, "  -- CUR: mSet=" + Arrays.toString(cur.mPref.mSetComponents));
                        Slog.i(TAG, "  -- CUR: mComponent=" + cur.mPref.mShortComponent);
                        Slog.i(TAG, "  -- NEW: mMatch=" + (match & IntentFilter.MATCH_CATEGORY_MASK));
                        Slog.i(TAG, "  -- CUR: mSet=" + Arrays.toString(set));
                        Slog.i(TAG, "  -- CUR: mComponent=" + activity.flattenToShortString());
                    }
                }
                if (cur.mPref.mAlways && cur.mPref.mComponent.equals(activity) && cur.mPref.mMatch == (match & IntentFilter.MATCH_CATEGORY_MASK) && cur.mPref.sameSet(set)) {
                    // Setting the preferred activity to what it happens to be already
                    if (DEBUG_PREFERRED) {
                        Slog.i(TAG, "Replacing with same preferred activity " + cur.mPref.mShortComponent + " for user " + userId + ":");
                        filter.dump(new LogPrinter(Log.INFO, TAG), "  ");
                    }
                    return;
                }
            }
            if (existing != null) {
                if (DEBUG_PREFERRED) {
                    Slog.i(TAG, existing.size() + " existing preferred matches for:");
                    filter.dump(new LogPrinter(Log.INFO, TAG), "  ");
                }
                for (int i = 0; i < existing.size(); i++) {
                    PreferredActivity pa = existing.get(i);
                    if (DEBUG_PREFERRED) {
                        Slog.i(TAG, "Removing existing preferred activity " + pa.mPref.mComponent + ":");
                        pa.dump(new LogPrinter(Log.INFO, TAG), "  ");
                    }
                    pir.removeFilter(pa);
                }
            }
        }
        addPreferredActivityInternal(filter, match, set, activity, true, userId, "Replacing preferred");
    }
}
Also used : LogPrinter(android.util.LogPrinter)

Example 43 with LogPrinter

use of android.util.LogPrinter in project android_frameworks_base by DirtyUnicorns.

the class Settings method applyDefaultPreferredActivityLPw.

private void applyDefaultPreferredActivityLPw(PackageManagerService service, IntentFilter tmpPa, ComponentName cn, int userId) {
    // preferred activity entry.
    if (PackageManagerService.DEBUG_PREFERRED) {
        Log.d(TAG, "Processing preferred:");
        tmpPa.dump(new LogPrinter(Log.DEBUG, TAG), "  ");
    }
    Intent intent = new Intent();
    int flags = PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
    intent.setAction(tmpPa.getAction(0));
    for (int i = 0; i < tmpPa.countCategories(); i++) {
        String cat = tmpPa.getCategory(i);
        if (cat.equals(Intent.CATEGORY_DEFAULT)) {
            flags |= MATCH_DEFAULT_ONLY;
        } else {
            intent.addCategory(cat);
        }
    }
    boolean doNonData = true;
    boolean hasSchemes = false;
    for (int ischeme = 0; ischeme < tmpPa.countDataSchemes(); ischeme++) {
        boolean doScheme = true;
        String scheme = tmpPa.getDataScheme(ischeme);
        if (scheme != null && !scheme.isEmpty()) {
            hasSchemes = true;
        }
        for (int issp = 0; issp < tmpPa.countDataSchemeSpecificParts(); issp++) {
            Uri.Builder builder = new Uri.Builder();
            builder.scheme(scheme);
            PatternMatcher ssp = tmpPa.getDataSchemeSpecificPart(issp);
            builder.opaquePart(ssp.getPath());
            Intent finalIntent = new Intent(intent);
            finalIntent.setData(builder.build());
            applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, ssp, null, null, userId);
            doScheme = false;
        }
        for (int iauth = 0; iauth < tmpPa.countDataAuthorities(); iauth++) {
            boolean doAuth = true;
            IntentFilter.AuthorityEntry auth = tmpPa.getDataAuthority(iauth);
            for (int ipath = 0; ipath < tmpPa.countDataPaths(); ipath++) {
                Uri.Builder builder = new Uri.Builder();
                builder.scheme(scheme);
                if (auth.getHost() != null) {
                    builder.authority(auth.getHost());
                }
                PatternMatcher path = tmpPa.getDataPath(ipath);
                builder.path(path.getPath());
                Intent finalIntent = new Intent(intent);
                finalIntent.setData(builder.build());
                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, auth, path, userId);
                doAuth = doScheme = false;
            }
            if (doAuth) {
                Uri.Builder builder = new Uri.Builder();
                builder.scheme(scheme);
                if (auth.getHost() != null) {
                    builder.authority(auth.getHost());
                }
                Intent finalIntent = new Intent(intent);
                finalIntent.setData(builder.build());
                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, auth, null, userId);
                doScheme = false;
            }
        }
        if (doScheme) {
            Uri.Builder builder = new Uri.Builder();
            builder.scheme(scheme);
            Intent finalIntent = new Intent(intent);
            finalIntent.setData(builder.build());
            applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, null, null, userId);
        }
        doNonData = false;
    }
    for (int idata = 0; idata < tmpPa.countDataTypes(); idata++) {
        String mimeType = tmpPa.getDataType(idata);
        if (hasSchemes) {
            Uri.Builder builder = new Uri.Builder();
            for (int ischeme = 0; ischeme < tmpPa.countDataSchemes(); ischeme++) {
                String scheme = tmpPa.getDataScheme(ischeme);
                if (scheme != null && !scheme.isEmpty()) {
                    Intent finalIntent = new Intent(intent);
                    builder.scheme(scheme);
                    finalIntent.setDataAndType(builder.build(), mimeType);
                    applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, null, null, userId);
                }
            }
        } else {
            Intent finalIntent = new Intent(intent);
            finalIntent.setType(mimeType);
            applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, null, null, null, null, userId);
        }
        doNonData = false;
    }
    if (doNonData) {
        applyDefaultPreferredActivityLPw(service, intent, flags, cn, null, null, null, null, userId);
    }
}
Also used : IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) Uri(android.net.Uri) PatternMatcher(android.os.PatternMatcher) LogPrinter(android.util.LogPrinter)

Example 44 with LogPrinter

use of android.util.LogPrinter in project android_frameworks_base by DirtyUnicorns.

the class IntentResolver method buildResolveList.

private void buildResolveList(Intent intent, FastImmutableArraySet<String> categories, boolean debug, boolean defaultOnly, String resolvedType, String scheme, F[] src, List<R> dest, int userId) {
    final String action = intent.getAction();
    final Uri data = intent.getData();
    final String packageName = intent.getPackage();
    final boolean excludingStopped = intent.isExcludingStopped();
    final Printer logPrinter;
    final PrintWriter logPrintWriter;
    if (debug) {
        logPrinter = new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM);
        logPrintWriter = new FastPrintWriter(logPrinter);
    } else {
        logPrinter = null;
        logPrintWriter = null;
    }
    final int N = src != null ? src.length : 0;
    boolean hasNonDefaults = false;
    int i;
    F filter;
    for (i = 0; i < N && (filter = src[i]) != null; i++) {
        int match;
        if (debug)
            Slog.v(TAG, "Matching against filter " + filter);
        if (excludingStopped && isFilterStopped(filter, userId)) {
            if (debug) {
                Slog.v(TAG, "  Filter's target is stopped; skipping");
            }
            continue;
        }
        // Is delivery being limited to filters owned by a particular package?
        if (packageName != null && !isPackageForFilter(packageName, filter)) {
            if (debug) {
                Slog.v(TAG, "  Filter is not from package " + packageName + "; skipping");
            }
            continue;
        }
        // Are we verified ?
        if (filter.getAutoVerify()) {
            if (localVerificationLOGV || debug) {
                Slog.v(TAG, "  Filter verified: " + isFilterVerified(filter));
                int authorities = filter.countDataAuthorities();
                for (int z = 0; z < authorities; z++) {
                    Slog.v(TAG, "   " + filter.getDataAuthority(z).getHost());
                }
            }
        }
        // Do we already have this one?
        if (!allowFilterResult(filter, dest)) {
            if (debug) {
                Slog.v(TAG, "  Filter's target already added");
            }
            continue;
        }
        match = filter.match(action, resolvedType, scheme, data, categories, TAG);
        if (match >= 0) {
            if (debug)
                Slog.v(TAG, "  Filter matched!  match=0x" + Integer.toHexString(match) + " hasDefault=" + filter.hasCategory(Intent.CATEGORY_DEFAULT));
            if (!defaultOnly || filter.hasCategory(Intent.CATEGORY_DEFAULT)) {
                final R oneResult = newResult(filter, match, userId);
                if (oneResult != null) {
                    dest.add(oneResult);
                    if (debug) {
                        dumpFilter(logPrintWriter, "    ", filter);
                        logPrintWriter.flush();
                        filter.dump(logPrinter, "    ");
                    }
                }
            } else {
                hasNonDefaults = true;
            }
        } else {
            if (debug) {
                String reason;
                switch(match) {
                    case IntentFilter.NO_MATCH_ACTION:
                        reason = "action";
                        break;
                    case IntentFilter.NO_MATCH_CATEGORY:
                        reason = "category";
                        break;
                    case IntentFilter.NO_MATCH_DATA:
                        reason = "data";
                        break;
                    case IntentFilter.NO_MATCH_TYPE:
                        reason = "type";
                        break;
                    default:
                        reason = "unknown reason";
                        break;
                }
                Slog.v(TAG, "  Filter did not match: " + reason);
            }
        }
    }
    if (debug && hasNonDefaults) {
        if (dest.size() == 0) {
            Slog.v(TAG, "resolveIntent failed: found match, but none with CATEGORY_DEFAULT");
        } else if (dest.size() > 1) {
            Slog.v(TAG, "resolveIntent: multiple matches, only some with CATEGORY_DEFAULT");
        }
    }
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) PrintWriterPrinter(android.util.PrintWriterPrinter) LogPrinter(android.util.LogPrinter) Printer(android.util.Printer) Uri(android.net.Uri) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) LogPrinter(android.util.LogPrinter)

Example 45 with LogPrinter

use of android.util.LogPrinter in project android_frameworks_base by DirtyUnicorns.

the class ActivityThread method main.

public static void main(String[] args) {
    Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "ActivityThreadMain");
    SamplingProfilerIntegration.start();
    // CloseGuard defaults to true and can be quite spammy.  We
    // disable it here, but selectively enable it later (via
    // StrictMode) on debug builds, but using DropBox, not logs.
    CloseGuard.setEnabled(false);
    Environment.initForCurrentUser();
    // Set the reporter for event logging in libcore
    EventLogger.setReporter(new EventLoggingReporter());
    // Make sure TrustedCertificateStore looks in the right place for CA certificates
    final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId());
    TrustedCertificateStore.setDefaultUserDirectory(configDir);
    Process.setArgV0("<pre-initialized>");
    Looper.prepareMainLooper();
    ActivityThread thread = new ActivityThread();
    thread.attach(false);
    if (sMainThreadHandler == null) {
        sMainThreadHandler = thread.getHandler();
    }
    if (false) {
        Looper.myLooper().setMessageLogging(new LogPrinter(Log.DEBUG, "ActivityThread"));
    }
    // End of event ActivityThreadMain.
    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
    Looper.loop();
    throw new RuntimeException("Main thread loop unexpectedly exited");
}
Also used : AndroidRuntimeException(android.util.AndroidRuntimeException) File(java.io.File) LogPrinter(android.util.LogPrinter)

Aggregations

LogPrinter (android.util.LogPrinter)52 Uri (android.net.Uri)10 Editable (android.text.Editable)7 Spannable (android.text.Spannable)7 SpannableStringBuilder (android.text.SpannableStringBuilder)7 AndroidRuntimeException (android.util.AndroidRuntimeException)7 ActivityInfo (android.content.pm.ActivityInfo)6 ResolveInfo (android.content.pm.ResolveInfo)6 Intent (android.content.Intent)5 IntentFilter (android.content.IntentFilter)5 PatternMatcher (android.os.PatternMatcher)5 PrintWriterPrinter (android.util.PrintWriterPrinter)5 Printer (android.util.Printer)5 FastPrintWriter (com.android.internal.util.FastPrintWriter)5 File (java.io.File)5 PrintWriter (java.io.PrintWriter)5 EphemeralResolveInfo (android.content.pm.EphemeralResolveInfo)4 Handler (android.os.Handler)2 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1