Cesarsk / Android-App-Say_it

Say It! App
Apache License 2.0
3 stars 1 forks source link

Huawei App Protected #63

Closed Cesarsk closed 7 years ago

Cesarsk commented 7 years ago

Huawei and other brands have a functionality called "App Protected".

By default, an app is not protected and it doesn't send notifications.

Adding a ifHuaweiAlert() method might be useful to check whether we're dealing with a Huawei smartphone and launch a dialog that warns the user to add this app as Protected App.

Cesarsk commented 7 years ago
private void ifHuaweiAlert() {
     final SharedPreferences settings = getSharedPreferences("ProtectedApps", MODE_PRIVATE);
      final String saveIfSkip = "skipProtectedAppsMessage";
      boolean skipMessage = settings.getBoolean(saveIfSkip, false);
     if (!skipMessage) {
         final SharedPreferences.Editor editor = settings.edit();
         Intent intent = new Intent();
         intent.setClassName("com.huawei.systemmanager","com.huawei.systemmanager.optimize.process.ProtectActivity");
    if (isCallable(intent)) {
        final AppCompatCheckBox dontShowAgain = new AppCompatCheckBox(this);
        dontShowAgain.setText("Do not show again");
        dontShowAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                editor.putBoolean(saveIfSkip, isChecked);
                editor.apply();
            }
        });

        new AlertDialog.Builder(this)
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle("Huawei Protected Apps")
                .setMessage(String.format("%s requires to be enabled in 'Protected Apps' to function properly.%n", getString(R.string.app_name)))
                .setView(dontShowAgain)
                .setPositiveButton("Protected Apps", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        huaweiProtectedApps();
                    }
                })
                .setNegativeButton(android.R.string.cancel, null)
                .show();
    } else {
        editor.putBoolean(saveIfSkip, true);
        editor.apply();
    }
}}