简体   繁体   中英

How to prevent another package/activity from running on the device through my application?

I have an app which has system privileges. My app displays a UI when the device starts after reboot. Issue is, another activity (not part of my app) also launches, therefore backgrounding my activity.

//my activity starts
ActivityManager: START u0 {flg=0x10000000 cmp=com.company.myApp/.activities.MyActivity} from uid 10097 on display 0

..... stuff happening -> UI is being updated 

// some other activity starts (automatically)
ActivityManager: START u0 {act=com.company.someOtherApp.Presentation.APL_RenderDocument flg=0x18000000 pkg=com.company.test cmp=com.company.test/.SomeOtherActivity (has extras)} from uid 10082 on display 0

// my activity goes into background.
MyActivity: onPause()
MyActivity: onStop()

Is there a way to prevent this other application from being created (or from being run)?

I'm looking into 2 particular methods

setComponentEnabledSetting()

Set the enabled setting for a package component (activity, receiver, service, provider). This setting will override any enabled state which may have been set by the component in its manifest.

setApplicationEnabledSetting()

Set the enabled setting for an application This setting will override any enabled state which may have been set by the application in its manifest. It also overrides the enabled state set in the manifest for any of the application's components. It does not override any enabled state set by setComponentEnabledSetting(ComponentName, int, int) for any of the application's components.

I don't quite understand the difference of if those methods can do what I want to achieve.

If an "enabled setting"/"enabled state" for a package/application is set to disabled, does that mean that application or package never gets invoked?

Is there another approach?

There are two ways as far I know

One is kill process

Process.killProcess( APP-PROCESS-ID )

Or you can kill background processes with activity manager liek this

ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
am.killBackgroundProcesses(packageName);

Declare this permission KILL_BACKGROUND_PROCESSES

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM