android.content.ComponentName#flattenToString ( )源码实例Demo

下面列出了android.content.ComponentName#flattenToString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: MediaSessionService.java
public void rememberMediaButtonReceiverLocked(MediaSessionRecord record) {
    PendingIntent receiver = record.getMediaButtonReceiver();
    mLastMediaButtonReceiver = receiver;
    mRestoredMediaButtonReceiver = null;
    String componentName = "";
    if (receiver != null) {
        ComponentName component = receiver.getIntent().getComponent();
        if (component != null
                && record.getPackageName().equals(component.getPackageName())) {
            componentName = component.flattenToString();
        }
    }
    Settings.Secure.putStringForUser(mContentResolver,
            Settings.System.MEDIA_BUTTON_RECEIVER,
            componentName + COMPONENT_NAME_USER_ID_DELIM + record.getUserId(),
            mFullUserId);
}
 
源代码2 项目: ViewDebugHelper   文件: ViewDebugHelperService.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        event.getWindowId();
        ComponentName componentName = new ComponentName(event.getPackageName().toString(), event.getClassName().toString());
        ActivityInfo activityInfo = ActivityHelper.tryGetActivity(this, componentName);
        boolean isActivity = activityInfo != null;
        if (isActivity) {
            String activityName = componentName.flattenToString();
            log("CurrentActivity" + activityName);
            ViewDebugHelperApplication.getInstance().setLastTopActivityName(activityName);
            ActivityStackManager.getInstance().offer(activityName);
        }
    }
}
 
源代码3 项目: Taskbar   文件: DesktopIconInfoTest.java
@Before
public void setUp() {
    context = ApplicationProvider.getApplicationContext();
    packageName = context.getPackageName();
    Drawable icon = context.getResources().getDrawable(R.drawable.tb_apps);
    ComponentName componentName = new ComponentName(context, MainActivity.class);
    appEntry =
            new AppEntry(
                    packageName,
                    componentName.flattenToString(),
                    packageName,
                    icon,
                    false
            );
    desktopIconInfo = new DesktopIconInfo(defaultColumn, defaultRow, appEntry);
}
 
源代码4 项目: TurboLauncher   文件: LauncherModel.java
/**
 * Returns true if the shortcuts already exists in the database. we identify
 * a shortcut by the component name of the intent.
 */
static boolean appWasRestored(Context context, Intent intent) {
	final ContentResolver cr = context.getContentResolver();
	final ComponentName component = intent.getComponent();
	if (component == null) {
		return false;
	}
	String componentName = component.flattenToString();
	final String where = "intent glob \"*component=" + componentName
			+ "*\" and restored = 1";
	Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
			new String[] { "intent", "restored" }, where, null, null);
	boolean result = false;
	try {
		result = c.moveToFirst();
	} finally {
		c.close();
	}

	return result;
}
 
源代码5 项目: android_9.0.0_r45   文件: StringFilter.java
@Override
public String getValue(ComponentName resolvedComponent, Intent intent,
        String resolvedType) {
    if (resolvedComponent != null) {
        return resolvedComponent.flattenToString();
    }
    return null;
}
 
源代码6 项目: Taskbar   文件: AppEntryTest.java
@Before
public void setUp() {
    context = ApplicationProvider.getApplicationContext();
    componentName = new ComponentName(context, MainActivity.class);
    icon = context.getResources().getDrawable(R.drawable.tb_apps);
    appEntry = new AppEntry(
            context.getPackageName(),
            componentName.flattenToString(),
            context.getPackageName(),
            icon,
            true
    );
}
 
/**
 * リクエストに含まれるセッションキーを変換する.
 * <p>
 * セッションキーにデバイスプラグインIDとreceiverを追加する。
 * 下記のように、分解できるようになっている。
 *
 * 【セッションキー.デバイスプラグイン[email protected]】
 * </p>
 * @param request リクエスト
 * @param plugin  デバイスプラグイン
 */
public void appendPluginIdToSessionKey(final Intent request, final DevicePlugin plugin) {
    String sessionKey = request.getStringExtra(DConnectMessage.EXTRA_SESSION_KEY);
    if (plugin != null && sessionKey != null) {
        sessionKey = sessionKey + DConnectConst.SEPARATOR + plugin.getPluginId();
        ComponentName receiver = (ComponentName) request.getExtras().get(DConnectMessage.EXTRA_RECEIVER);
        if (receiver != null) {
            sessionKey = sessionKey + DConnectConst.SEPARATOR_SESSION + receiver.flattenToString();
        }
        request.putExtra(DConnectMessage.EXTRA_SESSION_KEY, sessionKey);
    }
}
 
源代码8 项目: TurboLauncher   文件: Folder.java
private String getComponentString() {
    int size = mItemsInReadingOrder.size();
    String components = "";
    for (int i = 0; i < size; i++) {
        View v = mItemsInReadingOrder.get(i);
        Object tag = v.getTag();
        if (tag instanceof ShortcutInfo) {
            ComponentName componentName = ((ShortcutInfo) tag).getIntent().getComponent();
            components += componentName.flattenToString() + "|";
        }
    }

    return components;
}
 
private void processDisconnect(final ServiceConnection connection) {
    synchronized (mLock) {
        // The wallpaper disappeared.  If this isn't a system-default one, track
        // crashes and fall back to default if it continues to misbehave.
        if (connection == mWallpaper.connection) {
            final ComponentName wpService = mWallpaper.wallpaperComponent;
            if (!mWallpaper.wallpaperUpdating
                    && mWallpaper.userId == mCurrentUserId
                    && !Objects.equals(mDefaultWallpaperComponent, wpService)
                    && !Objects.equals(mImageWallpaper, wpService)) {
                // There is a race condition which causes
                // {@link #mWallpaper.wallpaperUpdating} to be false even if it is
                // currently updating since the broadcast notifying us is async.
                // This race is overcome by the general rule that we only reset the
                // wallpaper if its service was shut down twice
                // during {@link #MIN_WALLPAPER_CRASH_TIME} millis.
                if (mWallpaper.lastDiedTime != 0
                        && mWallpaper.lastDiedTime + MIN_WALLPAPER_CRASH_TIME
                        > SystemClock.uptimeMillis()) {
                    Slog.w(TAG, "Reverting to built-in wallpaper!");
                    clearWallpaperLocked(true, FLAG_SYSTEM, mWallpaper.userId, null);
                } else {
                    mWallpaper.lastDiedTime = SystemClock.uptimeMillis();

                    clearWallpaperComponentLocked(mWallpaper);
                    if (bindWallpaperComponentLocked(
                            wpService, false, false, mWallpaper, null)) {
                        mWallpaper.connection.scheduleTimeoutLocked();
                    } else {
                        Slog.w(TAG, "Reverting to built-in wallpaper!");
                        clearWallpaperLocked(true, FLAG_SYSTEM, mWallpaper.userId, null);
                    }
                }
                final String flattened = wpService.flattenToString();
                EventLog.writeEvent(EventLogTags.WP_WALLPAPER_CRASHED,
                        flattened.substring(0, Math.min(flattened.length(),
                                MAX_WALLPAPER_COMPONENT_LOG_LENGTH)));
            }
        } else {
            if (DEBUG_LIVE) {
                Slog.i(TAG, "Wallpaper changed during disconnect tracking; ignoring");
            }
        }
    }
}
 
源代码10 项目: android_9.0.0_r45   文件: SettingsStringUtil.java
@Override
protected String itemToString(ComponentName item) {
    return item.flattenToString();
}
 
源代码11 项目: Taskbar   文件: UTest.java
@Test
public void testIsAccessibilityServiceEnabled() {
    String enabledServices =
            Settings.Secure.getString(
                    context.getContentResolver(),
                    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES
            );
    ComponentName componentName = new ComponentName(context, PowerMenuService.class);
    String flattenString = componentName.flattenToString();
    String flattenShortString = componentName.flattenToShortString();
    String newEnabledService =
            enabledServices == null ?
                    "" :
                    enabledServices
                            .replaceAll(":" + flattenString, "")
                            .replaceAll(":" + flattenShortString, "")
                            .replaceAll(flattenString, "")
                            .replaceAll(flattenShortString, "");
    Settings.Secure.putString(
            context.getContentResolver(),
            Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
            newEnabledService
    );
    assertFalse(U.isAccessibilityServiceEnabled(context));
    Settings.Secure.putString(
            context.getContentResolver(),
            Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
            newEnabledService + ":" + flattenString
    );
    assertTrue(U.isAccessibilityServiceEnabled(context));
    Settings.Secure.putString(
            context.getContentResolver(),
            Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
            newEnabledService + ":" + flattenShortString
    );
    assertTrue(U.isAccessibilityServiceEnabled(context));
    Settings.Secure.putString(
            context.getContentResolver(),
            Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
            enabledServices
    );
}
 
源代码12 项目: CumulusTV   文件: CumulusChannel.java
public Builder setPluginSource(@NonNull ComponentName pluginComponent) {
    if (pluginComponent != null) {
        cumulusChannel.pluginSource = pluginComponent.flattenToString();
    }
    return this;
}
 
源代码13 项目: ActivityForceNewTask   文件: XposedMod.java
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
    if (!lpparam.packageName.equals("android"))
        return;

    XC_MethodHook hook = new XC_MethodHook() {
        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            settingsHelper.reload();
            if (settingsHelper.isModDisabled())
                return;
            Intent intent = (Intent) XposedHelpers.getObjectField(param.thisObject, "intent");

            // The launching app does not expect data back. It's safe to run the activity in a
            // new task.
            int requestCode = getIntField(param.thisObject, "requestCode");
            if (requestCode != -1)
                return;

            // The intent already has FLAG_ACTIVITY_NEW_TASK set, no need to do anything.
            if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) == Intent.FLAG_ACTIVITY_NEW_TASK)
                return;

            String intentAction = intent.getAction();
            // If the intent is not a known safe intent (as in, the launching app does not expect
            // data back, so it's safe to run in a new task,) ignore it straight away.
            if (intentAction == null)
                return;

            // If the app is launching one of its own activities, we shouldn't open it in a new task.
            int uid = ((ActivityInfo) getObjectField(param.thisObject, "info")).applicationInfo.uid;
            if (getIntField(param.thisObject, "launchedFromUid") == uid)
                return;

            ComponentName componentName = (ComponentName) getObjectField(param.thisObject, "realActivity");
            String componentNameString = componentName.flattenToString();
            // Log if necessary.
            if (settingsHelper.isLogEnabled()) {
                // Get context
                Context context = AndroidAppHelper.currentApplication();

                if (context != null)
                    context.sendBroadcast(new Intent(Common.INTENT_LOG).putExtra(Common.INTENT_COMPONENT_EXTRA, componentNameString));
                else
                    XposedBridge.log("activityforcenewtask: couldn't get context.");
                XposedBridge.log("activityforcenewtask: componentString: " + componentNameString);
            }

            // If the blacklist is used and the component is in the blacklist, or if the
            // whitelist is used and the component isn't whitelisted, we shouldn't modify
            // the intent's flags.
            boolean isListed = settingsHelper.isListed(componentNameString);
            String listType = settingsHelper.getListType();
            if ((listType.equals(Common.PREF_BLACKLIST) && isListed) ||
                    (listType.equals(Common.PREF_WHITELIST) && !isListed))
                return;

            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
    };

    Class ActivityRecord = findClass("com.android.server.am.ActivityRecord", lpparam.classLoader);
    XposedBridge.hookAllConstructors(ActivityRecord, hook);
}