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

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

/**
 * Gets the activity or application icon for an activity.
 * Uses the local icon cache for fast repeated lookups.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the activity nor the application
 *         has an icon set.
 */
private Drawable getActivityIconWithCache(ComponentName component) {
    // First check the icon cache
    String componentIconKey = component.flattenToShortString();
    // Using containsKey() since we also store null values.
    if (mOutsideDrawablesCache.containsKey(componentIconKey)) {
        Drawable.ConstantState cached = mOutsideDrawablesCache.get(componentIconKey);
        return cached == null ? null : cached.newDrawable(mProviderContext.getResources());
    }
    // Then try the activity or application icon
    Drawable drawable = getActivityIcon(component);
    // Stick it in the cache so we don't do this lookup again.
    Drawable.ConstantState toCache = drawable == null ? null : drawable.getConstantState();
    mOutsideDrawablesCache.put(componentIconKey, toCache);
    return drawable;
}
 
源代码2 项目: android_9.0.0_r45   文件: ServiceRecord.java
ServiceRecord(ActivityManagerService ams,
        BatteryStatsImpl.Uid.Pkg.Serv servStats, ComponentName name,
        Intent.FilterComparison intent, ServiceInfo sInfo, boolean callerIsFg,
        Runnable restarter) {
    this.ams = ams;
    this.stats = servStats;
    this.name = name;
    shortName = name.flattenToShortString();
    this.intent = intent;
    serviceInfo = sInfo;
    appInfo = sInfo.applicationInfo;
    packageName = sInfo.applicationInfo.packageName;
    processName = sInfo.processName;
    permission = sInfo.permission;
    exported = sInfo.exported;
    this.restarter = restarter;
    createRealTime = SystemClock.elapsedRealtime();
    lastActivity = SystemClock.uptimeMillis();
    userId = UserHandle.getUserId(appInfo.uid);
    createdFromFg = callerIsFg;
}
 
源代码3 项目: android_9.0.0_r45   文件: SuggestionsAdapter.java
/**
 * Gets the activity or application icon for an activity.
 * Uses the local icon cache for fast repeated lookups.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the activity nor the application
 *         has an icon set.
 */
private Drawable getActivityIconWithCache(ComponentName component) {
    // First check the icon cache
    String componentIconKey = component.flattenToShortString();
    // Using containsKey() since we also store null values.
    if (mOutsideDrawablesCache.containsKey(componentIconKey)) {
        Drawable.ConstantState cached = mOutsideDrawablesCache.get(componentIconKey);
        return cached == null ? null : cached.newDrawable(mProviderContext.getResources());
    }
    // Then try the activity or application icon
    Drawable drawable = getActivityIcon(component);
    // Stick it in the cache so we don't do this lookup again.
    Drawable.ConstantState toCache = drawable == null ? null : drawable.getConstantState();
    mOutsideDrawablesCache.put(componentIconKey, toCache);
    return drawable;
}
 
源代码4 项目: CSipSimple   文件: SuggestionsAdapter.java
/**
 * Gets the activity or application icon for an activity.
 * Uses the local icon cache for fast repeated lookups.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the activity nor the application
 *         has an icon set.
 */
private Drawable getActivityIconWithCache(ComponentName component) {
    // First check the icon cache
    String componentIconKey = component.flattenToShortString();
    // Using containsKey() since we also store null values.
    if (mOutsideDrawablesCache.containsKey(componentIconKey)) {
        Drawable.ConstantState cached = mOutsideDrawablesCache.get(componentIconKey);
        return cached == null ? null : cached.newDrawable(mProviderContext.getResources());
    }
    // Then try the activity or application icon
    Drawable drawable = getActivityIcon(component);
    // Stick it in the cache so we don't do this lookup again.
    Drawable.ConstantState toCache = drawable == null ? null : drawable.getConstantState();
    mOutsideDrawablesCache.put(componentIconKey, toCache);
    return drawable;
}
 
源代码5 项目: budget-watch   文件: MainActivityTest.java
@Test
public void testFirstRunStartsIntro()
{
    prefs.edit().remove("firstrun").commit();

    ActivityController controller = Robolectric.buildActivity(MainActivity.class).create();
    Activity activity = (Activity)controller.get();

    assertTrue(activity.isFinishing() == false);

    Intent next = shadowOf(activity).getNextStartedActivity();

    ComponentName componentName = next.getComponent();
    String name = componentName.flattenToShortString();
    assertEquals("protect.budgetwatch/.intro.IntroActivity", name);

    Bundle extras = next.getExtras();
    assertNull(extras);

    assertEquals(false, prefs.getBoolean("firstrun", true));
}
 
源代码6 项目: android-job   文件: WakeLockUtil.java
/**
 * Do a {@link android.content.Context#startService(android.content.Intent)
 * Context.startService}, but holding a wake lock while the service starts.
 * This will modify the Intent to hold an extra identifying the wake lock;
 * when the service receives it in {@link android.app.Service#onStartCommand
 * Service.onStartCommand}, it should pass back the Intent it receives there to
 * {@link #completeWakefulIntent(android.content.Intent)} in order to release
 * the wake lock.
 *
 * @param context The Context in which it operate.
 * @param intent The Intent with which to start the service, as per
 * {@link android.content.Context#startService(android.content.Intent)
 * Context.startService}.
 */
public static ComponentName startWakefulService(Context context, Intent intent) {
    synchronized (ACTIVE_WAKE_LOCKS) {
        int id = nextId;
        nextId++;
        if (nextId <= 0) {
            nextId = 1;
        }

        intent.putExtra(EXTRA_WAKE_LOCK_ID, id);
        ComponentName comp = context.startService(intent);
        if (comp == null) {
            return null;
        }

        String tag = "wake:" + comp.flattenToShortString();
        PowerManager.WakeLock wakeLock = acquireWakeLock(context, tag, TimeUnit.MINUTES.toMillis(3));
        if (wakeLock != null) {
            ACTIVE_WAKE_LOCKS.put(id, wakeLock);
        }

        return comp;
    }
}
 
源代码7 项目: zen4android   文件: SuggestionsAdapter.java
/**
 * Gets the activity or application icon for an activity.
 * Uses the local icon cache for fast repeated lookups.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the activity nor the application
 *         has an icon set.
 */
private Drawable getActivityIconWithCache(ComponentName component) {
    // First check the icon cache
    String componentIconKey = component.flattenToShortString();
    // Using containsKey() since we also store null values.
    if (mOutsideDrawablesCache.containsKey(componentIconKey)) {
        Drawable.ConstantState cached = mOutsideDrawablesCache.get(componentIconKey);
        return cached == null ? null : cached.newDrawable(mProviderContext.getResources());
    }
    // Then try the activity or application icon
    Drawable drawable = getActivityIcon(component);
    // Stick it in the cache so we don't do this lookup again.
    Drawable.ConstantState toCache = drawable == null ? null : drawable.getConstantState();
    mOutsideDrawablesCache.put(componentIconKey, toCache);
    return drawable;
}
 
源代码8 项目: AndroidComponentPlugin   文件: PackageParser.java
public String getComponentShortName() {
    if (componentShortName != null) {
        return componentShortName;
    }
    ComponentName component = getComponentName();
    if (component != null) {
        componentShortName = component.flattenToShortString();
    }
    return componentShortName;
}
 
源代码9 项目: AndroidComponentPlugin   文件: PackageParser.java
public String getComponentShortName() {
    if (componentShortName != null) {
        return componentShortName;
    }
    ComponentName component = getComponentName();
    if (component != null) {
        componentShortName = component.flattenToShortString();
    }
    return componentShortName;
}
 
源代码10 项目: AndroidComponentPlugin   文件: PackageParser.java
public String getComponentShortName() {
    if (componentShortName != null) {
        return componentShortName;
    }
    ComponentName component = getComponentName();
    if (component != null) {
        componentShortName = component.flattenToShortString();
    }
    return componentShortName;
}
 
源代码11 项目: android_9.0.0_r45   文件: PreferredComponent.java
public PreferredComponent(Callbacks callbacks, int match, ComponentName[] set,
        ComponentName component, boolean always) {
    mCallbacks = callbacks;
    mMatch = match&IntentFilter.MATCH_CATEGORY_MASK;
    mComponent = component;
    mAlways = always;
    mShortComponent = component.flattenToShortString();
    mParseError = null;
    if (set != null) {
        final int N = set.length;
        String[] myPackages = new String[N];
        String[] myClasses = new String[N];
        String[] myComponents = new String[N];
        for (int i=0; i<N; i++) {
            ComponentName cn = set[i];
            if (cn == null) {
                mSetPackages = null;
                mSetClasses = null;
                mSetComponents = null;
                return;
            }
            myPackages[i] = cn.getPackageName().intern();
            myClasses[i] = cn.getClassName().intern();
            myComponents[i] = cn.flattenToShortString();
        }
        mSetPackages = myPackages;
        mSetClasses = myClasses;
        mSetComponents = myComponents;
    } else {
        mSetPackages = null;
        mSetClasses = null;
        mSetComponents = null;
    }
}
 
源代码12 项目: android_9.0.0_r45   文件: IntentFirewall.java
private static void logIntent(int intentType, Intent intent, int callerUid,
        String resolvedType) {
    // The component shouldn't be null, but let's double check just to be safe
    ComponentName cn = intent.getComponent();
    String shortComponent = null;
    if (cn != null) {
        shortComponent = cn.flattenToShortString();
    }

    String callerPackages = null;
    int callerPackageCount = 0;
    IPackageManager pm = AppGlobals.getPackageManager();
    if (pm != null) {
        try {
            String[] callerPackagesArray = pm.getPackagesForUid(callerUid);
            if (callerPackagesArray != null) {
                callerPackageCount = callerPackagesArray.length;
                callerPackages = joinPackages(callerPackagesArray);
            }
        } catch (RemoteException ex) {
            Slog.e(TAG, "Remote exception while retrieving packages", ex);
        }
    }

    EventLogTags.writeIfwIntentMatched(intentType, shortComponent, callerUid,
            callerPackageCount, callerPackages, intent.getAction(), resolvedType,
            intent.getDataString(), intent.getFlags());
}
 
源代码13 项目: android_9.0.0_r45   文件: TrustAgentService.java
@Override
public void onCreate() {
    super.onCreate();
    ComponentName component = new ComponentName(this, getClass());
    try {
        ServiceInfo serviceInfo = getPackageManager().getServiceInfo(component, 0 /* flags */);
        if (!Manifest.permission.BIND_TRUST_AGENT.equals(serviceInfo.permission)) {
            throw new IllegalStateException(component.flattenToShortString()
                    + " is not declared with the permission "
                    + "\"" + Manifest.permission.BIND_TRUST_AGENT + "\"");
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Can't get ServiceInfo for " + component.toShortString());
    }
}
 
private static String extractServiceId(ComponentName name, Bundle metaData) {
  if (metaData != null && metaData.containsKey(METADATA_KEY_CLASS_NAME_OVERRIDE)) {
    return name.getPackageName() + "/" + metaData.getString(METADATA_KEY_CLASS_NAME_OVERRIDE);
  } else {
    return name.flattenToShortString();
  }
}
 
源代码15 项目: island   文件: ApiActivity.java
private void onIntent(final Intent intent) {
	Log.i(TAG, "API request: " + intent.toUri(0));
	if (intent.getAction() != null) {
		String result;
		final ComponentName caller = getCallingActivity();
		if (caller != null) try { @SuppressLint("WrongConstant")		// Invoked with startActivityForResult()
			final ActivityInfo info = getPackageManager().getActivityInfo(caller, Hacks.MATCH_ANY_USER_AND_UNINSTALLED);
			int uid = info.applicationInfo.uid;
			if (UserHandles.getUserId(uid) != 0) {
				final String[] potential_pkgs = getPackageManager().getPackagesForUid(uid);
				if (potential_pkgs == null) uid = UserHandles.getAppId(uid);	// Fix the incorrect UID when MATCH_ANY_USER is used.
			}
			result = ApiDispatcher.verifyCaller(this, intent, caller.getPackageName(), uid);
		} catch (final PackageManager.NameNotFoundException e) {
			result = "Unverifiable caller activity: " + caller.flattenToShortString();
		} else result = ApiDispatcher.verifyCaller(this, intent, null, - 1);

		if (result == null) {
			result = ApiDispatcher.dispatch(this, intent);
			if (result == null) {
				setResult(Activity.RESULT_OK);
				Log.i(TAG, "API result: Success");
			} else {
				setResult(Activity.RESULT_CANCELED, new Intent(result));
				Log.i(TAG, "API result: " + result);
			}
		} else {
			setResult(Api.latest.RESULT_UNVERIFIED_IDENTITY, new Intent(result));
			Log.w(TAG, "Unverified client: " + result);
		}
	} else setResult(RESULT_CANCELED, new Intent("No action"));
	finish();
}
 
源代码16 项目: WeChatHongBao   文件: HongbaoService.java
/**
 * 获取当前activity名称
 *  @param event
 *  @return
 *
 */
private String getCurrentActivity(AccessibilityEvent event) {
    ComponentName componentName = new ComponentName(
            event.getPackageName().toString(),
            event.getClassName().toString()
    );

    try {
        getPackageManager().getActivityInfo(componentName, 0);
        return componentName.flattenToShortString();

    } catch (PackageManager.NameNotFoundException e) {
        return "";
    }
}
 
源代码17 项目: 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
    );
}
 
源代码18 项目: TurboLauncher   文件: IconCache.java
private static String getResourceFilename(ComponentName component) {
	String resourceName = component.flattenToShortString();
	String filename = resourceName.replace(File.separatorChar, '_');
	return RESOURCE_FILE_PREFIX + filename;
}
 
源代码19 项目: LB-Launcher   文件: IconCache.java
private static String getResourceFilename(ComponentName component) {
    String resourceName = component.flattenToShortString();
    String filename = resourceName.replace(File.separatorChar, '_');
    return RESOURCE_FILE_PREFIX + filename;
}
 
源代码20 项目: Hangar   文件: IconCacheHelper.java
protected static String getResourceFilename(ComponentName component) {
    return component.flattenToShortString();
}