16dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk/* 26dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk * Copyright (C) 2015 The Android Open Source Project 36dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk * 46dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk * Licensed under the Apache License, Version 2.0 (the "License"); 56dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk * you may not use this file except in compliance with the License. 66dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk * You may obtain a copy of the License at 76dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk * 86dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk * http://www.apache.org/licenses/LICENSE-2.0 96dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk * 106dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk * Unless required by applicable law or agreed to in writing, software 116dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk * distributed under the License is distributed on an "AS IS" BASIS, 126dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk * See the License for the specific language governing permissions and 146dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk * limitations under the License. 156dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk */ 166dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkpackage com.android.packageinstaller.permission.utils; 176dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk 186dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkimport android.Manifest; 196dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkimport android.app.AlertDialog; 206dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkimport android.content.Context; 216dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkimport android.content.DialogInterface; 226dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkimport android.content.DialogInterface.OnClickListener; 236dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkimport android.content.Intent; 246dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkimport android.content.res.Resources; 256dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkimport android.location.ILocationManager; 266dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkimport android.location.LocationManager; 276dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkimport android.os.RemoteException; 286dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkimport android.os.ServiceManager; 296dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkimport android.provider.Settings; 306dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk 316dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkimport com.android.packageinstaller.R; 326dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk 336dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkimport java.util.ArrayList; 346dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk 356dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monkpublic class LocationUtils { 366dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk 376dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk public static final String LOCATION_PERMISSION = Manifest.permission_group.LOCATION; 386dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk 396dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk public static void showLocationDialog(final Context context, CharSequence label) { 406dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk new AlertDialog.Builder(context) 41ef861375eebd9ac6cce7c0bb163380ab1c951063Svetoslav .setIcon(R.drawable.ic_dialog_alert_material) 426dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk .setTitle(android.R.string.dialog_alert_title) 436dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk .setMessage(context.getString(R.string.location_warning, label)) 446dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk .setNegativeButton(R.string.ok, null) 456dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk .setPositiveButton(R.string.location_settings, new OnClickListener() { 466dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk @Override 476dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk public void onClick(DialogInterface dialog, int which) { 486dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); 496dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk } 506dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk }) 516dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk .show(); 526dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk } 536dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk 546dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk public static boolean isLocationEnabled(Context context) { 556dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk return Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE, 566dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk Settings.Secure.LOCATION_MODE_OFF) != Settings.Secure.LOCATION_MODE_OFF; 576dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk } 586dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk 59acd09293116133b6a86d348e011d8347a03266ecSvetoslav public static boolean isLocationGroupAndProvider(String groupName, String packageName) { 606dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk return LOCATION_PERMISSION.equals(groupName) && isNetworkLocationProvider(packageName); 616dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk } 626dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk 636dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk private static boolean isNetworkLocationProvider(String packageName) { 646dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk ILocationManager locationService = ILocationManager.Stub.asInterface( 656dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk ServiceManager.getService(Context.LOCATION_SERVICE)); 666dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk try { 676dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk return packageName.equals(locationService.getNetworkProviderPackage()); 686dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk } catch (RemoteException e) { 696dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk return false; 706dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk } 716dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk } 726dc9e5007de25dd9dd8fd6ebc42d9322069a9a38Jason Monk} 73