Search in sources :

Example 36 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class ActivityTestMain method setExclude.

void setExclude(boolean exclude) {
    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.AppTask> tasks = am.getAppTasks();
    int taskId = getTaskId();
    for (int i = 0; i < tasks.size(); i++) {
        ActivityManager.AppTask task = tasks.get(i);
        if (task.getTaskInfo().id == taskId) {
            task.setExcludeFromRecents(exclude);
        }
    }
}
Also used : ActivityManager(android.app.ActivityManager)

Example 37 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class ActivityTestMain method addAppRecents.

void addAppRecents(int count) {
    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    intent.setComponent(new ComponentName(this, ActivityTestMain.class));
    for (int i = 0; i < count; i++) {
        ActivityManager.TaskDescription desc = new ActivityManager.TaskDescription();
        desc.setLabel("Added #" + i);
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
        if ((i & 1) == 0) {
            desc.setIcon(bitmap);
        }
        int taskId = am.addAppTask(this, intent, desc, bitmap);
        Log.i(TAG, "Added new task id #" + taskId);
    }
}
Also used : Bitmap(android.graphics.Bitmap) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ComponentName(android.content.ComponentName) ActivityManager(android.app.ActivityManager)

Example 38 with ActivityManager

use of android.app.ActivityManager in project LshUtils by SenhLinsh.

the class AppUtils method gc.

/**
     * 清理后台进程与服务
     *
     * @return 被清理的数量
     */
public static int gc(Context context) {
    long i = getDeviceUsableMemory(context);
    // 清理掉的进程数
    int count = 0;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    // 获取正在运行的service列表
    List<RunningServiceInfo> serviceList = am.getRunningServices(100);
    if (serviceList != null) {
        for (RunningServiceInfo service : serviceList) {
            if (service.pid == android.os.Process.myPid())
                continue;
            try {
                android.os.Process.killProcess(service.pid);
                count++;
            } catch (Exception e) {
                e.getStackTrace();
            }
        }
    }
    // 获取正在运行的进程列表
    List<RunningAppProcessInfo> processList = am.getRunningAppProcesses();
    if (processList != null) {
        for (RunningAppProcessInfo process : processList) {
            // 一般数值大于RunningAppProcessInfo.IMPORTANCE_VISIBLE的进程都是非可见进程,也就是在后台运行着
            if (process.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
                // pkgList 得到该进程下运行的包名
                String[] pkgList = process.pkgList;
                for (String pkgName : pkgList) {
                    if (DEBUG) {
                    }
                    try {
                        am.killBackgroundProcesses(pkgName);
                        count++;
                    } catch (Exception e) {
                        // 防止意外发生
                        e.getStackTrace();
                    }
                }
            }
        }
    }
    if (DEBUG) {
    }
    return count;
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ActivityManager(android.app.ActivityManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 39 with ActivityManager

use of android.app.ActivityManager in project LshUtils by SenhLinsh.

the class AppUtils method isServiceRunning.

/**
     * 检查服务是否正在运行
     */
public static boolean isServiceRunning(Context context, Class<? extends Service> service) {
    //获取Activity管理器
    ActivityManager manager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
    //获取运行中服务
    List<RunningServiceInfo> services = manager.getRunningServices(1000);
    String serviceName = service.getName();
    for (RunningServiceInfo info : services) {
        //获取每一条运行中的服务的类名并判断
        String name = info.service.getClassName();
        if (TextUtils.equals(serviceName, name)) {
            return true;
        }
    }
    return false;
}
Also used : RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ActivityManager(android.app.ActivityManager)

Example 40 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class ResolverActivity method onCreate.

protected void onCreate(Bundle savedInstanceState, Intent intent, CharSequence title, int defaultTitleRes, Intent[] initialIntents, List<ResolveInfo> rList, boolean alwaysUseOption) {
    setTheme(R.style.Theme_DeviceDefault_Resolver);
    super.onCreate(savedInstanceState);
    // Determine whether we should show that intent is forwarded
    // from managed profile to owner or other way around.
    setProfileSwitchMessageId(intent.getContentUserHint());
    try {
        mLaunchedFromUid = ActivityManagerNative.getDefault().getLaunchedFromUid(getActivityToken());
    } catch (RemoteException e) {
        mLaunchedFromUid = -1;
    }
    if (mLaunchedFromUid < 0 || UserHandle.isIsolated(mLaunchedFromUid)) {
        // Gulp!
        finish();
        return;
    }
    mPm = getPackageManager();
    mPackageMonitor.register(this, getMainLooper(), false);
    mRegistered = true;
    final ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    mIconDpi = am.getLauncherLargeIconDensity();
    // Add our initial intent as the first item, regardless of what else has already been added.
    mIntents.add(0, new Intent(intent));
    final String referrerPackage = getReferrerPackageName();
    mResolverComparator = new ResolverComparator(this, getTargetIntent(), referrerPackage);
    if (configureContentView(mIntents, initialIntents, rList, alwaysUseOption)) {
        return;
    }
    final ResolverDrawerLayout rdl = (ResolverDrawerLayout) findViewById(R.id.contentPanel);
    if (rdl != null) {
        rdl.setOnDismissedListener(new ResolverDrawerLayout.OnDismissedListener() {

            @Override
            public void onDismissed() {
                finish();
            }
        });
        if (isVoiceInteraction()) {
            rdl.setCollapsed(false);
        }
        mResolverDrawerLayout = rdl;
    }
    if (title == null) {
        title = getTitleForAction(intent.getAction(), defaultTitleRes);
    }
    if (!TextUtils.isEmpty(title)) {
        final TextView titleView = (TextView) findViewById(R.id.title);
        if (titleView != null) {
            titleView.setText(title);
        }
        setTitle(title);
        // Try to initialize the title icon if we have a view for it and a title to match
        final ImageView titleIcon = (ImageView) findViewById(R.id.title_icon);
        if (titleIcon != null) {
            ApplicationInfo ai = null;
            try {
                if (!TextUtils.isEmpty(referrerPackage)) {
                    ai = mPm.getApplicationInfo(referrerPackage, 0);
                }
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Could not find referrer package " + referrerPackage);
            }
            if (ai != null) {
                titleIcon.setImageDrawable(ai.loadIcon(mPm));
            }
        }
    }
    final ImageView iconView = (ImageView) findViewById(R.id.icon);
    final DisplayResolveInfo iconInfo = mAdapter.getFilteredItem();
    if (iconView != null && iconInfo != null) {
        new LoadIconIntoViewTask(iconInfo, iconView).execute();
    }
    if (alwaysUseOption || mAdapter.hasFilteredItem()) {
        final ViewGroup buttonLayout = (ViewGroup) findViewById(R.id.button_bar);
        if (buttonLayout != null) {
            buttonLayout.setVisibility(View.VISIBLE);
            mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always);
            mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once);
        } else {
            mAlwaysUseOption = false;
        }
    }
    if (mAdapter.hasFilteredItem()) {
        setAlwaysButtonEnabled(true, mAdapter.getFilteredPosition(), false);
        mOnceButton.setEnabled(true);
    }
    mProfileView = findViewById(R.id.profile_button);
    if (mProfileView != null) {
        mProfileView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                final DisplayResolveInfo dri = mAdapter.getOtherProfile();
                if (dri == null) {
                    return;
                }
                // Do not show the profile switch message anymore.
                mProfileSwitchMessageId = -1;
                onTargetSelected(dri, false);
                finish();
            }
        });
        bindProfileView();
    }
    if (isVoiceInteraction()) {
        onSetupVoiceInteraction();
    }
    final Set<String> categories = intent.getCategories();
    MetricsLogger.action(this, mAdapter.hasFilteredItem() ? MetricsProto.MetricsEvent.ACTION_SHOW_APP_DISAMBIG_APP_FEATURED : MetricsProto.MetricsEvent.ACTION_SHOW_APP_DISAMBIG_NONE_FEATURED, intent.getAction() + ":" + intent.getType() + ":" + (categories != null ? Arrays.toString(categories.toArray()) : ""));
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ViewGroup(android.view.ViewGroup) ApplicationInfo(android.content.pm.ApplicationInfo) LabeledIntent(android.content.pm.LabeledIntent) Intent(android.content.Intent) ActivityManager(android.app.ActivityManager) ResolverDrawerLayout(com.android.internal.widget.ResolverDrawerLayout) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) RemoteException(android.os.RemoteException)

Aggregations

ActivityManager (android.app.ActivityManager)612 Intent (android.content.Intent)61 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)55 PackageManager (android.content.pm.PackageManager)50 Context (android.content.Context)47 ComponentName (android.content.ComponentName)44 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)36 ArrayList (java.util.ArrayList)31 View (android.view.View)29 IOException (java.io.IOException)29 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)27 SuppressLint (android.annotation.SuppressLint)26 ImageView (android.widget.ImageView)25 TextView (android.widget.TextView)25 IActivityManager (android.app.IActivityManager)19 Point (android.graphics.Point)19 RemoteException (android.os.RemoteException)19 MemoryInfo (android.app.ActivityManager.MemoryInfo)18 Bitmap (android.graphics.Bitmap)18 AdapterView (android.widget.AdapterView)18