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.Context; 19 import android.content.Intent; 20 import android.os.Build; 21 import android.util.Log; 22 import com.android.google.gce.gceservice.GceFuture; 23 import com.android.google.gce.gceservice.JobBase; 24 25 /** 26 * Configure Location Services on Android Jellybean. 27 * No action on more recent versions of Android. 28 */ 29 class LocationServicesManager extends JobBase { 30 private static final String LOG_TAG = "GceLocationServicesManager"; 31 private static final String ACTION_LOCATION_SERVICES_CONSENT_INTENT = 32 "com.google.android.gsf.action.SET_USE_LOCATION_FOR_SERVICES"; 33 private static final String EXTRA_LOCATION_SERVICES_CONSENT_DISABLE = 34 "disable"; 35 private final Context mContext; 36 private final GceFuture<Boolean> mResult = new GceFuture<Boolean>("Location Services"); 37 38 39 LocationServicesManager(Context context) { 40 super(LOG_TAG); 41 mContext = context; 42 } 43 44 45 public int execute() { 46 /* Check if we're running Jellybean. 47 * Sadly, we can't use version name Build.VERSION_CODES.JELLY_BEAN_MR2 48 * because MR1 and MR0 don't know this number. 49 */ 50 if (Build.VERSION.SDK_INT <= 18) { 51 Intent intent = new Intent(); 52 intent.setAction(ACTION_LOCATION_SERVICES_CONSENT_INTENT); 53 intent.setFlags(intent.getFlags() | 54 Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); 55 intent.putExtra(EXTRA_LOCATION_SERVICES_CONSENT_DISABLE, false); 56 mContext.startActivity(intent); 57 } 58 59 mResult.set(true); 60 return 0; 61 } 62 63 64 public void onDependencyFailed(Exception e) { 65 Log.e(LOG_TAG, "Could not configure LocationServices.", e); 66 mResult.set(e); 67 } 68 69 70 public GceFuture<Boolean> getLocationServicesReady() { 71 return mResult; 72 } 73 } 74