All Products
Search
Document Center

Mobile Platform as a Service:Use privacy permission pop-ups (Portal&Bundle)

Last Updated:Jul 12, 2023

The regulatory authority requires that the app cannot call related sensitive APIs before the user clicks the Agree button in the privacy agreement dialog box. In response to this regulatory requirement, the baselines of mPaaS Android 10.1.32.17 or later versions and 10.1.60.5 or later versions are supported. Refer to this topic to modify the project according to your actual situation.

Procedure

Important

The Activity that pops up the privacy dialog box cannot inherit the BaseActivity of mPaaS, because BaseActivity will collect embedded data, which will cause the App to collect private data before agreeing to the privacy policy.

  1. Create a new callback class of privacy permission dialog box. Create a new class and implement the PrivacyListener API operation. For the implementation of the class, see the following code:

    public class MyPrivacyListener implements PrivacyListener {
     // Make a privacy permission dialog box in this method
     @Override
     public void showPrivacy(final Activity activity, final PrivacyResultCallback privacyResultCallback) {
         if(null==privacyResultCallback){
             return;
         }
         if(null!=activity){
             new AlertDialog.Builder(activity)
                     .setTitle("Privacy permission dialog box")
                     .setMessage("Main content")
                     .setPositiveButton("Agree to continue to use", new DialogInterface.OnClickListener() {
                         @Override
                         public void onClick(DialogInterface dialogInterface, int i) {
                             // After you click OK, cancel the dialog box
                             dialogInterface.cancel();
                             // Set the dialog box result to true
                             privacyResultCallback.onResult(true);
                         }
                     })
                     .setNegativeButton("Disagree and exit", new DialogInterface.OnClickListener() {
                         @Override
                         public void onClick(DialogInterface dialogInterface, int i) {
                             // After you click Disagree, cancel the dialog box
                             dialogInterface.cancel();
                             // Set the dialog box result to false
                             privacyResultCallback.onResult(false);
                             // End the current activity, the framework will kill the process
                             if(null!=activity){
                                 activity.finish();
                             }
                         }
                     })
                     .setCancelable(false)
                     .create()
                     .show();
         }else{
             // If the activity is empty, the callback result is set to false
             privacyResultCallback.onResult(false);
         }
     }
    }

    If you are using a 10.1.68.42 and above baseline and need to clear the privacy state, please implement the PrivacyListener2 interface and implement the shouldClear function.

    The following code is a description of the shouldClear function:

    @Override
    public boolean shouldClear(Context context) {
      //When the user does not agree to the privacy agreement, the default is to use SharedPreferences to store false and set it to return false. If you need to pop up the window again, you need to set the true stored in the SP to return true;
      return false;//The value of return is the boolean value stored in SP.
    }

    During the callback, a dialog box must be used to trigger windowFocusChange. The framework will perform subsequent operations after triggering. Because the callback class will be reflectively initialized by the system framework and scheduled very early, do not add a constructor with a method name. In addition, do not add specific logic to the constructor. If you need to use resources in the dialog box, you need to use different methods under different baselines.

    • Under the 32 baseline, you need to use the following method:

      Resources resource = QuinoxAgent.getInstance().getResourcesByBundle("bundlename of the Bundle where the resource is located");
      Note

      The bundlename can be checked in /build/intermediates/bundle/META-INF/BUNDLE.MF in the main module of the Bundle project.

      bundlename
    • Under the 60 baseline, you need to create the res_slinks file under the main module of the Portal project, and write the group and artifact of the Bundle where your resources are located in the res_slinks file according to the rule. The rule is group-artifact.split("-")[0]. When the content is too long, you need to check whether the content is correct if you want to add a new line.For example:

      group = com.mpaas.demo.materialdesign`
      `artifact = materialdesign-build`

      The final configuration written into the res_slinks file is com.mpaas.demo.materialdesign-materialdesign. 1

      After completing the preceding content, you can directly use LayoutInflator.inflate(R.layout.xxx) to call resources.

  2. Register the callback class in AndroidManifest.Register the callback class of privacy permission dialog box in the AndroidManifest of portal, and value is the full path of the callback class implemented just now. The code is shown as follows. Note that you need to replace the full path and class name with your own callback class.

     <!--callback of privacy permission dialog box-->
     <meta-data
         android:name="privacy.listener"
         android:value="com.mpaas.demo.launcher.MyPrivacyListener" />
  3. Start up pop-up box interception. In the preInit of MockLauncherApplicationAgent, add the dialog box interception. The code is as follows:

     //Check if you want to display a privacy permission dialog box to the user
     if(! PrivacyUtil.isUserAgreed(getApplicationContext())){
         PermissionGate.getInstance().waitForUserConform(mContext, getMicroApplicationContext());
     }
  4. Start the first Activity. In the postInit of MockLauncherActivityAgent, do the first Activity jump. The code is as follows:

     // Determine whether the user privacy permission has been obtained
     if(PrivacyUtil.isUserAgreed(activity)){
         new Handler().postDelayed(new Runnable() {
             public void run() {
                 Intent intent = new Intent(activity, MainActivity.class);
                 activity.startActivity(intent);
                 activity.finish();
             }
         }, 200);
     }