1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.google.gce.gceservice; 17 18 import android.content.ContentResolver; 19 import android.content.Context; 20 import android.provider.Settings; 21 import android.provider.Settings.SettingNotFoundException; 22 import android.util.Log; 23 24 /** 25 * Disable package verifier. 26 */ 27 public class PackageVerifierManager extends JobBase { 28 private static final String LOG_TAG = "GcePackageVerifierManager"; 29 private static final String SETTING_PACKAGE_VERIFIER_ENABLE = "verifier_verify_adb_installs"; 30 private final Context mContext; 31 private final GceFuture<Boolean> mResult = 32 new GceFuture<Boolean>("Package Verifier"); 33 34 35 PackageVerifierManager(Context context) { 36 super(LOG_TAG); 37 mContext = context; 38 } 39 40 41 private boolean getAndLogPackageVerifierState() { 42 int package_verifier_state = 1; 43 try { 44 ContentResolver contentResolver = mContext.getContentResolver(); 45 package_verifier_state = Settings.Secure.getInt(contentResolver, SETTING_PACKAGE_VERIFIER_ENABLE); 46 } catch (SettingNotFoundException e) { 47 Log.w(LOG_TAG, "Could not read package verifier state. Assuming it's enabled."); 48 } 49 50 return package_verifier_state != 0; 51 } 52 53 54 public int execute() { 55 if (getAndLogPackageVerifierState()) { 56 Settings.Secure.putInt(mContext.getContentResolver(), SETTING_PACKAGE_VERIFIER_ENABLE, 0); 57 // One more call, just to log the state. 58 getAndLogPackageVerifierState(); 59 } 60 61 mResult.set(true); 62 return 0; 63 } 64 65 66 public void onDependencyFailed(Exception e) { 67 Log.e(LOG_TAG, "Could not disable Package Verifier.", e); 68 mResult.set(e); 69 } 70 71 72 public GceFuture<Boolean> getPackageVerifierReady() { 73 return mResult; 74 } 75 } 76