Search in sources :

Example 36 with LogPrinter

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

the class PackageManagerService method findPreferredActivity.

ResolveInfo findPreferredActivity(Intent intent, String resolvedType, int flags, List<ResolveInfo> query, int priority, int userId) {
    if (!sUserManager.exists(userId))
        return null;
    // writer
    synchronized (mPackages) {
        if (intent.getSelector() != null) {
            intent = intent.getSelector();
        }
        if (DEBUG_PREFERRED)
            intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION);
        PreferredIntentResolver pir = mSettings.mPreferredActivities.get(userId);
        List<PreferredActivity> prefs = pir != null ? pir.queryIntent(intent, resolvedType, (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0, userId) : null;
        if (prefs != null && prefs.size() > 0) {
            // First figure out how good the original match set is.
            // We will only allow preferred activities that came
            // from the same match quality.
            int match = 0;
            if (DEBUG_PREFERRED) {
                Log.v(TAG, "Figuring out best match...");
            }
            final int N = query.size();
            for (int j = 0; j < N; j++) {
                final ResolveInfo ri = query.get(j);
                if (DEBUG_PREFERRED) {
                    Log.v(TAG, "Match for " + ri.activityInfo + ": 0x" + Integer.toHexString(match));
                }
                if (ri.match > match) {
                    match = ri.match;
                }
            }
            if (DEBUG_PREFERRED) {
                Log.v(TAG, "Best match: 0x" + Integer.toHexString(match));
            }
            match &= IntentFilter.MATCH_CATEGORY_MASK;
            final int M = prefs.size();
            for (int i = 0; i < M; i++) {
                final PreferredActivity pa = prefs.get(i);
                if (pa.mPref.mMatch != match) {
                    continue;
                }
                final ActivityInfo ai = getActivityInfo(pa.mPref.mComponent, flags | PackageManager.GET_DISABLED_COMPONENTS, userId);
                if (DEBUG_PREFERRED) {
                    Log.v(TAG, "Got preferred activity:");
                    if (ai != null) {
                        ai.dump(new LogPrinter(Log.VERBOSE, TAG), "  ");
                    } else {
                        Log.v(TAG, "  null");
                    }
                }
                if (ai == null) {
                    // This previously registered preferred activity
                    // component is no longer known.  Most likely an update
                    // to the app was installed and in the new version this
                    // component no longer exists.  Clean it up by removing
                    // it from the preferred activities list, and skip it.
                    Slog.w(TAG, "Removing dangling preferred activity: " + pa.mPref.mComponent);
                    pir.removeFilter(pa);
                    continue;
                }
                for (int j = 0; j < N; j++) {
                    final ResolveInfo ri = query.get(j);
                    if (!ri.activityInfo.applicationInfo.packageName.equals(ai.applicationInfo.packageName)) {
                        continue;
                    }
                    if (!ri.activityInfo.name.equals(ai.name)) {
                        continue;
                    }
                    // user their preference.
                    if (!pa.mPref.sameSet(query, priority)) {
                        Slog.i(TAG, "Result set changed, dropping preferred activity for " + intent + " type " + resolvedType);
                        pir.removeFilter(pa);
                        return null;
                    }
                    // Yay!
                    return ri;
                }
            }
        }
    }
    return null;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) LogPrinter(android.util.LogPrinter)

Example 37 with LogPrinter

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

the class PackageManagerService method addPreferredActivity.

public void addPreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity, int userId) {
    // writer
    int callingUid = Binder.getCallingUid();
    enforceCrossUserPermission(callingUid, userId, true, "add 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 addPreferredActivity() from uid " + callingUid);
                return;
            }
            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
        }
        Slog.i(TAG, "Adding preferred activity " + activity + " for user " + userId + " :");
        filter.dump(new LogPrinter(Log.INFO, TAG), "  ");
        mSettings.editPreferredActivitiesLPw(userId).addFilter(new PreferredActivity(filter, match, set, activity));
        mSettings.writePackageRestrictionsLPr(userId);
    }
}
Also used : LogPrinter(android.util.LogPrinter)

Example 38 with LogPrinter

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

the class ConnectivityServiceTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    mServiceContext = new BroadcastInterceptingContext(getContext());
    mNetManager = mock(INetworkManagementService.class);
    mStatsService = mock(INetworkStatsService.class);
    mPolicyService = mock(INetworkPolicyManager.class);
    mNetFactory = mock(ConnectivityService.NetworkFactory.class);
    mMobile = new MockNetwork(TYPE_MOBILE);
    mWifi = new MockNetwork(TYPE_WIFI);
    // omit most network trackers
    doThrow(new IllegalArgumentException("Not supported in test environment")).when(mNetFactory).createTracker(anyInt(), isA(NetworkConfig.class));
    doReturn(mMobile.tracker).when(mNetFactory).createTracker(eq(TYPE_MOBILE), isA(NetworkConfig.class));
    doReturn(mWifi.tracker).when(mNetFactory).createTracker(eq(TYPE_WIFI), isA(NetworkConfig.class));
    final ArgumentCaptor<Handler> trackerHandler = ArgumentCaptor.forClass(Handler.class);
    doNothing().when(mMobile.tracker).startMonitoring(isA(Context.class), trackerHandler.capture());
    mService = new ConnectivityService(mServiceContext, mNetManager, mStatsService, mPolicyService, mNetFactory);
    mService.systemReady();
    mTrackerHandler = trackerHandler.getValue();
    mTrackerHandler.getLooper().setMessageLogging(new LogPrinter(Log.INFO, TAG));
}
Also used : Context(android.content.Context) INetworkManagementService(android.os.INetworkManagementService) NetworkConfig(android.net.NetworkConfig) Handler(android.os.Handler) INetworkPolicyManager(android.net.INetworkPolicyManager) INetworkStatsService(android.net.INetworkStatsService) LogPrinter(android.util.LogPrinter)

Example 39 with LogPrinter

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

the class BaseInputConnection method replaceText.

private void replaceText(CharSequence text, int newCursorPosition, boolean composing) {
    final Editable content = getEditable();
    if (content == null) {
        return;
    }
    beginBatchEdit();
    // delete composing text set previously.
    int a = getComposingSpanStart(content);
    int b = getComposingSpanEnd(content);
    if (DEBUG)
        Log.v(TAG, "Composing span: " + a + " to " + b);
    if (b < a) {
        int tmp = a;
        a = b;
        b = tmp;
    }
    if (a != -1 && b != -1) {
        removeComposingSpans(content);
    } else {
        a = Selection.getSelectionStart(content);
        b = Selection.getSelectionEnd(content);
        if (a < 0)
            a = 0;
        if (b < 0)
            b = 0;
        if (b < a) {
            int tmp = a;
            a = b;
            b = tmp;
        }
    }
    if (composing) {
        Spannable sp = null;
        if (!(text instanceof Spannable)) {
            sp = new SpannableStringBuilder(text);
            text = sp;
            ensureDefaultComposingSpans();
            if (mDefaultComposingSpans != null) {
                for (int i = 0; i < mDefaultComposingSpans.length; ++i) {
                    sp.setSpan(mDefaultComposingSpans[i], 0, sp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
                }
            }
        } else {
            sp = (Spannable) text;
        }
        setComposingSpans(sp);
    }
    if (DEBUG)
        Log.v(TAG, "Replacing from " + a + " to " + b + " with \"" + text + "\", composing=" + composing + ", type=" + text.getClass().getCanonicalName());
    if (DEBUG) {
        LogPrinter lp = new LogPrinter(Log.VERBOSE, TAG);
        lp.println("Current text:");
        TextUtils.dumpSpans(content, lp, "  ");
        lp.println("Composing text:");
        TextUtils.dumpSpans(text, lp, "  ");
    }
    // we are providing here.
    if (newCursorPosition > 0) {
        newCursorPosition += b - 1;
    } else {
        newCursorPosition += a;
    }
    if (newCursorPosition < 0)
        newCursorPosition = 0;
    if (newCursorPosition > content.length())
        newCursorPosition = content.length();
    Selection.setSelection(content, newCursorPosition);
    content.replace(a, b, text);
    if (DEBUG) {
        LogPrinter lp = new LogPrinter(Log.VERBOSE, TAG);
        lp.println("Final text:");
        TextUtils.dumpSpans(content, lp, "  ");
    }
    endBatchEdit();
}
Also used : Editable(android.text.Editable) Spannable(android.text.Spannable) SpannableStringBuilder(android.text.SpannableStringBuilder) LogPrinter(android.util.LogPrinter)

Example 40 with LogPrinter

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

the class PackageManagerService method findPersistentPreferredActivityLP.

private ResolveInfo findPersistentPreferredActivityLP(Intent intent, String resolvedType, int flags, List<ResolveInfo> query, boolean debug, int userId) {
    final int N = query.size();
    PersistentPreferredIntentResolver ppir = mSettings.mPersistentPreferredActivities.get(userId);
    // Get the list of persistent preferred activities that handle the intent
    if (DEBUG_PREFERRED || debug)
        Slog.v(TAG, "Looking for presistent preferred activities...");
    List<PersistentPreferredActivity> pprefs = ppir != null ? ppir.queryIntent(intent, resolvedType, (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0, userId) : null;
    if (pprefs != null && pprefs.size() > 0) {
        final int M = pprefs.size();
        for (int i = 0; i < M; i++) {
            final PersistentPreferredActivity ppa = pprefs.get(i);
            if (DEBUG_PREFERRED || debug) {
                Slog.v(TAG, "Checking PersistentPreferredActivity ds=" + (ppa.countDataSchemes() > 0 ? ppa.getDataScheme(0) : "<none>") + "\n  component=" + ppa.mComponent);
                ppa.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), "  ");
            }
            final ActivityInfo ai = getActivityInfo(ppa.mComponent, flags | MATCH_DISABLED_COMPONENTS, userId);
            if (DEBUG_PREFERRED || debug) {
                Slog.v(TAG, "Found persistent preferred activity:");
                if (ai != null) {
                    ai.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), "  ");
                } else {
                    Slog.v(TAG, "  null");
                }
            }
            if (ai == null) {
                // component is no longer known. Ignore it and do NOT remove it.
                continue;
            }
            for (int j = 0; j < N; j++) {
                final ResolveInfo ri = query.get(j);
                if (!ri.activityInfo.applicationInfo.packageName.equals(ai.applicationInfo.packageName)) {
                    continue;
                }
                if (!ri.activityInfo.name.equals(ai.name)) {
                    continue;
                }
                //  Found a persistent preference that can handle the intent.
                if (DEBUG_PREFERRED || debug) {
                    Slog.v(TAG, "Returning persistent preferred activity: " + ri.activityInfo.packageName + "/" + ri.activityInfo.name);
                }
                return ri;
            }
        }
    }
    return null;
}
Also used : EphemeralResolveInfo(android.content.pm.EphemeralResolveInfo) ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) 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