Mobile defender 12_ Software lock, application related

Source: Internet
Author: User
Tags log log password protection

1, software lock ( function Description : When the software is in the list of locking , Open this software will jump to the password input interface , input correctly jumps to the software interface , otherwise the password is wrong )

①ui Reference

Do not use fragment, with layout overlay hidden, click on a text to display an interface (list listview), another layout interface is hidden (framelayout frame layout implementation).

② Program Unlocked Interface Display

Find all the controls that are concerned, by default putting all apps unlocked in the interface list.

Reference Entry UI

Extra: Lock small icon with status selector, click Transform picture

The horizontal line may consider adding a width of 1 imageview;

③ Click on the entry to add to the locking list and remove it in the current list.

Because locking is a list entry that needs to be saved for a long time, the database is created to record the data.

Reference table name: lockinfo,_id, primary key self-growth, Packname application package name,

Then create the DAO class, manipulate the table's additions and deletions to change the logic.

If an exception occurs with a C code exception such as UNIX, it is possible that the emulator is dead.

Click Entry >> Add to database >> add data with lock entry.

Extra: When getting the application collection, the shunt: An locking application collection, an unlocked application collection. (Check the table to determine)

④ Lock Entry display: is also a ListView, note the right to unlock the small icon of the different.

In the entry Click event, if you click Add Lock, one collection is removed and another collection is added.

UI update: Put the toggle entry on the title

⑤ the animation effect of the entry, click to move to the left (unlock), click on the lock, move to the left.

Displacement animation.

The animation is played after clicking on the entry, but the animated effect appears on the next entry. (The code sequencing of the adapter. Notifydatasetchanged and animations does not affect.)

Because the animation's playback is not a blocking code (not in order from top to bottom code execution, but a timer is turned on.)

So to register an animated listener setanimationlistener (new XXX) {

Onanimationstart ()//Start playback

Onanimationrepeat ()//Repeat Play

Onanimationend ()//When the animation stops playing

}

2, the core principle of the program lock watchdog:

2.1 Observation log log, you can find that when the user opened the app Activitymanager will print a log, open the app.

So you just need to get the Activitymanager data to monitor the state of the system running.

The watchdog needs to be stationed in the background program for a long time, so a service needs to be created to get (non-stop) data

Open a sub-thread, a dead loop, or a timer can achieve the effect of constant access to data.

Am.getrunningtask (max task stack 1000)//Gets the running task, returning a running task stack collection.

The General Android task stack will not exceed 50,windows 100

Features of this API: most recently used in the front, last used on the last side.

RunningTaskInfo.topActivity.getPackageName ();

2.2 So just keep getting the first task in the running task stack and then judge it to achieve the watchdog effect.

It is important to note that the dead loop needs to be controlled by a variable to make it easier to close, or the child thread cannot shut down. At the same time, it is necessary to set a short delay for each time it gets data, otherwise it is easy to consume resources by iterating through thousands of cycles per second.

2.3 Add a new switch in the Setup Center: On, turn on, turn off, turn off the service

Remember to judge the state, to perform the echo state.

Permissions: Get_task get task Stack status

3, code implementation watchdog effect

3.1

① The watchdog runs, gets to the first task, then queries the database, determines whether it is protected, if yes, opens a password interface

Service Open Activiy, remember to add Flag,intent.setflag (Intent.flag_activiyt_new_task);

When the interface is opened, the application's package name is passed over to Intent.putextra (PackageName), and the password interface is displayed to make it easier for users to distinguish between the applications to be opened.

② Password Interface Reference UI:

③ password input is correct, finsh () off the current page, password input error, prompt error, input box Jitter (refer to the effect in the API demo)

After the password is entered correctly, you should tell the watchdog to stop detecting the app temporarily (send broadcast, bind remote service).

Here with custom broadcasts, if the password is entered correctly, send a custom broadcast, carry the package name (in order to temporarily stop the protection)

Receive this broadcast in the service, record the package name, determine whether the need to protect the end, and then determine whether the need to temporarily stop detection.

3.2 Bug Fix:

① User Click the return button, the password interface disappears, you can see the instant interface, so in the password input interface Click the Back button, let the user directly back to the desktop.

Rewrite ONBACKPRESSD ()//If the super () code is deleted, clicking Back will not close the interface.

You need to get the user back to the desktop.//View the upper application, the desktop source code.

When the user returns to the desktop and then opens the password-protected app, the password protection interface is the last app ②.

Solution: Close the interface when it is not visible.

③ opens the app to see an instant interface: The watchdog cycle time interval is too long and short.

3.3 If the mobile defender is turned on, after minimizing, open the protected application, enter the correct password, come to the interface is mobile phone defender, rather than want to open the application.

Cause: Because there are multiple interfaces on the mobile defender's task stack, the Password entry screen pops up when the protected app is opened. Mobile Defender task Stack There are two interfaces, the input is correct, the input password is correct just turn off the password input interface, will return to the phone defender's previous interface. Not a protected app.

Workaround: Activity Final mode: single instance SingleInstance

Development of the flexible use of the startup mode, you can solve some of the application of user experience bugs, improve program execution efficiency

3.4 Efficiency Optimization for Applications

① to extract some references out of the dead loop.

②am.getrunningtasks (1);//Only the tasks in the first task stack are needed.

③ watchdog query database operation is relatively time-consuming, so add a query all the protection of the application of the collection, so that every time the query, you do not have to query the database, directly query the collection (in memory, high efficiency) can.

④ initialization of the input password interface outside the dead loop

3.5, the bug caused after the optimization

① The Get Database collection operation was performed only once. If Add or remove does not work during service opening

Resolution: implemented by content watchers

Uri:content://xxxxxxx

In DAO Context.getcontentresolver (). Notifychange (URI, the observer of the notification (null, who registers who observes));

In the service class, create a content parser. Register Content Viewer (Uri,true (prefix is sufficient), content Viewer);

Create the Content observer internal class, Inherit Contentobserver, override the OnChange () method, and call when the data changes.

Once the change has occurred, retrieve the collection again.

Keywords: Observer design pattern

4. Power Optimization of program lock

Program lock in the background service has been performed, high power consumption.

When the user in the operation of the mobile phone watchdog behavior, the lock screen when the loop closed, the child thread is finished, unlock the screen when the child thread.

Both events will be broadcast, adding two action when the watchdog's internal broadcast receiver registers

When you receive the broadcast, filter the action.

Mobile defender 12_ Software lock, application related

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.