导航菜单

页面标题

页面副标题

Fix Locker v1.5 - EnableCosuActivity.java 源代码

正在查看: Fix Locker v1.5 应用的 EnableCosuActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.user.a4keygen.cosu;

import android.app.Activity;
import android.app.DownloadManager;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.PersistableBundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import com.android.setupwizardlib.SetupWizardLayout;
import com.android.setupwizardlib.view.NavigationBar;
import com.user.a4keygen.DeviceAdminReceiver;
import com.user.a4keygen.R;
import com.user.a4keygen.common.PackageInstallationUtils;
import com.user.a4keygen.policy.locktask.KioskModeActivity;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class EnableCosuActivity extends Activity {
    public static final String BUNDLE_KEY_COSU_CONFIG = "cosu-demo-config-location";
    private static final String MODE_CUSTOM = "custom";
    private static final String MODE_DEFAULT = "default";
    private static final String MODE_SINGLE = "single";
    private CosuConfig mConfig;
    private Long mConfigDownloadId;
    private DownloadManager mDownloadManager;
    private TextView mStatusText;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            int i = message.what;
            if (i == 1) {
                if (EnableCosuActivity.this.mConfigDownloadId.equals(message.obj)) {
                    EnableCosuActivity.this.onConfigFileDownloaded();
                    removeMessages(2, EnableCosuActivity.this.mConfigDownloadId);
                    return;
                }
                Long onDownloadComplete = EnableCosuActivity.this.mConfig.onDownloadComplete((Long) message.obj);
                if (onDownloadComplete != null) {
                    removeMessages(2, onDownloadComplete);
                }
                if (EnableCosuActivity.this.mConfig.areAllInstallsFinished()) {
                    EnableCosuActivity.this.startCosuMode();
                    return;
                }
                return;
            }
            if (i != 2) {
                if (i != 3) {
                    return;
                }
                EnableCosuActivity.this.mConfig.onInstallComplete((String) message.obj);
                if (EnableCosuActivity.this.mConfig.areAllInstallsFinished()) {
                    EnableCosuActivity.this.startCosuMode();
                    return;
                }
                return;
            }
            long longValue = ((Long) message.obj).longValue();
            if (longValue != EnableCosuActivity.this.mConfigDownloadId.longValue()) {
                EnableCosuActivity.this.mDownloadManager.remove(longValue);
                Log.e(CosuUtils.TAG, "Time out during app download with id: " + longValue);
            } else {
                Log.e(CosuUtils.TAG, "Time out during download of config file");
                EnableCosuActivity.this.mDownloadManager.remove(EnableCosuActivity.this.mConfigDownloadId.longValue());
            }
            EnableCosuActivity.this.finishWithFailure();
        }
    };
    private BroadcastReceiver mDownloadReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if ("android.intent.action.DOWNLOAD_COMPLETE".equals(intent.getAction())) {
                EnableCosuActivity.this.mHandler.sendMessage(EnableCosuActivity.this.mHandler.obtainMessage(1, new Long(intent.getLongExtra("extra_download_id", 0L))));
            }
        }
    };
    private BroadcastReceiver mInstallReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (PackageInstallationUtils.ACTION_INSTALL_COMPLETE.equals(intent.getAction())) {
                int intExtra = intent.getIntExtra("android.content.pm.extra.STATUS", 1);
                String stringExtra = intent.getStringExtra("android.content.pm.extra.PACKAGE_NAME");
                if (intExtra == -1) {
                    EnableCosuActivity.this.startActivity((Intent) intent.getParcelableExtra("android.intent.extra.INTENT"));
                } else if (intExtra == 0) {
                    EnableCosuActivity.this.mHandler.sendMessage(EnableCosuActivity.this.mHandler.obtainMessage(3, stringExtra));
                } else {
                    Log.e(CosuUtils.TAG, "Install failed.");
                    EnableCosuActivity.this.finishWithFailure();
                }
            }
        }
    };

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (!((DevicePolicyManager) getSystemService("device_policy")).isDeviceOwnerApp(getPackageName())) {
            Log.e(CosuUtils.TAG, "EMISAFE is not the device owner, cannot set up COSU device.");
            finish();
            return;
        }
        PersistableBundle persistableBundle = (PersistableBundle) getIntent().getParcelableExtra("android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE");
        if (persistableBundle == null) {
            Log.e(CosuUtils.TAG, "No admin extra bundle");
            finish();
            return;
        }
        setContentView(R.layout.enable_cosu_activity);
        SetupWizardLayout findViewById = findViewById(R.id.setup_wizard_layout);
        NavigationBar navigationBar = findViewById.getNavigationBar();
        navigationBar.getNextButton().setVisibility(8);
        navigationBar.getBackButton().setVisibility(8);
        findViewById.showProgressBar();
        this.mStatusText = (TextView) findViewById(R.id.status_text);
        this.mDownloadManager = (DownloadManager) getSystemService("download");
        registerReceiver(this.mDownloadReceiver, new IntentFilter("android.intent.action.DOWNLOAD_COMPLETE"));
        registerReceiver(this.mInstallReceiver, new IntentFilter(PackageInstallationUtils.ACTION_INSTALL_COMPLETE));
        String str = (String) persistableBundle.get(BUNDLE_KEY_COSU_CONFIG);
        if (str == null) {
            Log.e(CosuUtils.TAG, "No download-location specified");
            finishWithFailure();
        } else {
            this.mConfigDownloadId = CosuUtils.startDownload(this.mDownloadManager, this.mHandler, str);
            this.mStatusText.setText(getString(R.string.setup_cosu_status_download));
        }
    }

    public void onConfigFileDownloaded() {
        this.mStatusText.setText(getString(R.string.setup_cosu_status_parse));
        try {
            CosuConfig createConfig = CosuConfig.createConfig(this, new FileInputStream(this.mDownloadManager.openDownloadedFile(this.mConfigDownloadId.longValue()).getFileDescriptor()));
            this.mConfig = createConfig;
            if (createConfig == null) {
                finishWithFailure();
                return;
            }
            Log.d(CosuUtils.TAG, "CosuConfig:");
            Log.d(CosuUtils.TAG, this.mConfig.toString());
            if (!this.mConfig.applyPolicies(DeviceAdminReceiver.getComponentName(this))) {
                finishWithFailure();
                return;
            }
            this.mConfig.initiateDownloadAndInstall(this.mHandler);
            this.mStatusText.setText(getString(R.string.setup_cosu_status_apps));
            if (this.mConfig.areAllInstallsFinished()) {
                startCosuMode();
            }
        } catch (FileNotFoundException e) {
            Log.e(CosuUtils.TAG, "Download file not found.", e);
            finishWithFailure();
        }
    }

    public void startCosuMode() {
        Intent intent;
        String mode = this.mConfig.getMode();
        String[] kioskApps = this.mConfig.getKioskApps();
        if (mode == null) {
            mode = MODE_DEFAULT;
        }
        if (MODE_CUSTOM.equals(mode)) {
            intent = new Intent(this, (Class<?>) KioskModeActivity.class);
            intent.putExtra(KioskModeActivity.LOCKED_APP_PACKAGE_LIST, kioskApps);
            getPackageManager().setComponentEnabledSetting(new ComponentName(getPackageName(), KioskModeActivity.class.getName()), 1, 1);
        } else if (MODE_SINGLE.equals(mode)) {
            intent = kioskApps.length != 0 ? getPackageManager().getLaunchIntentForPackage(kioskApps[0]) : null;
        } else {
            intent = new Intent("android.intent.action.MAIN");
            intent.addCategory("android.intent.category.HOME");
        }
        if (intent == null) {
            Log.e(CosuUtils.TAG, "No launch intent specified. Mode=" + mode);
            finishWithFailure();
            return;
        }
        intent.addFlags(268435456);
        startActivity(intent);
        Toast.makeText(this, R.string.setup_cosu_success, 1).show();
        unregisterReceiver(this.mInstallReceiver);
        unregisterReceiver(this.mDownloadReceiver);
        if (this.mHandler.hasMessages(2)) {
            Log.w(CosuUtils.TAG, "Download timeout messages remaining on handler thread.");
            this.mHandler.removeMessages(2);
        }
        finish();
    }

    public void finishWithFailure() {
        Toast.makeText(this, R.string.setup_cosu_failure, 1).show();
        unregisterReceiver(this.mInstallReceiver);
        unregisterReceiver(this.mDownloadReceiver);
        this.mHandler.removeMessages(2);
        finish();
    }
}