Skip to content

Commit

Permalink
Location: Solve the problem of multiple pop-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
DaVinci9196 committed Apr 25, 2024
1 parent 49ea8b6 commit 569f45a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.Manifest
import android.app.Activity
import android.content.DialogInterface
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.os.Handler
import android.os.Looper
Expand All @@ -25,6 +26,7 @@ import com.google.android.gms.location.LocationRequest
import com.google.android.gms.location.LocationSettingsRequest
import org.microg.gms.location.core.R
import org.microg.gms.location.manager.AskPermissionActivity
import org.microg.gms.location.manager.EXTRA_GRANT_RESULTS
import org.microg.gms.location.manager.EXTRA_MESSENGER
import org.microg.gms.location.manager.EXTRA_PERMISSIONS
import org.microg.gms.ui.buildAlertDialog
Expand All @@ -45,8 +47,15 @@ class LocationSettingsCheckerActivity : Activity(), DialogInterface.OnCancelList
private var requests: List<LocationRequest>? = null
private var callingPackage: String? = null

private val mgLocationPermission = arrayOf(
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION
)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d(TAG, "LocationSettingsCheckerActivity onCreate")
callingPackage = callingActivity?.packageName
if (callingPackage == null) {
Log.e(TAG, "Started without calling activity set")
Expand Down Expand Up @@ -129,7 +138,7 @@ class LocationSettingsCheckerActivity : Activity(), DialogInterface.OnCancelList
item.findViewById<ImageView>(android.R.id.icon).setImageDrawable(
when (improvement) {
Improvement.GPS_AND_NLP -> ContextCompat.getDrawable(this, R.drawable.ic_gps)
Improvement.PERMISSIONS -> ContextCompat.getDrawable(this, R.drawable.ic_gms)
Improvement.PERMISSIONS -> ContextCompat.getDrawable(this, R.drawable.ic_mg)
else -> {
Log.w(TAG, "Unsupported improvement: $improvement")
null
Expand All @@ -148,14 +157,16 @@ class LocationSettingsCheckerActivity : Activity(), DialogInterface.OnCancelList
when (improvement) {
Improvement.PERMISSIONS -> {
val intent = Intent(this, AskPermissionActivity::class.java)
intent.putExtra(
EXTRA_PERMISSIONS,
arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION)
)
intent.putExtra(EXTRA_PERMISSIONS, mgLocationPermission)
intent.putExtra(EXTRA_MESSENGER, Messenger(object : Handler(Looper.getMainLooper()) {
override fun handleMessage(msg: Message) {
if (msg.what == RESULT_OK) {
checkImprovements()
if (msg.what == RESULT_OK ) {
val grantResults = msg.data?.getIntArray(EXTRA_GRANT_RESULTS) ?: IntArray(0)
if (grantResults.size == mgLocationPermission.size && grantResults.all { it == PackageManager.PERMISSION_GRANTED }) {
checkImprovements()
} else {
finishResult(RESULT_CANCELED)
}
} else {
finishResult(RESULT_CANCELED)
}
Expand Down
23 changes: 0 additions & 23 deletions play-services-location/core/src/main/res/drawable/ic_gms.xml

This file was deleted.

24 changes: 24 additions & 0 deletions play-services-location/core/src/main/res/drawable/ic_mg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="144"
android:viewportHeight="144">
<path
android:pathData="M135.64,94.6C126.06,118.82 108.89,133.49 83.59,138.31C47.45,145.2 9.9,116.32 6.9,79.88C5.59,63.88 7.28,48.83 16.87,35.5C23.34,26.49 31.19,19.34 41.18,13.71C61.77,2.11 82.28,2.44 102.71,12.21C114.74,17.96 124.59,27.05 131.31,39.01C141.3,56.75 141.36,75.25 135.64,94.6M89.65,29.71C88.39,29.28 87.15,28.79 85.87,28.43C67.52,23.19 47.84,29.62 36.32,44.59C24.57,59.87 23.38,80.68 33.33,97.04C43.23,113.32 62.09,121.99 80.74,118.84C100.39,115.51 116.37,99.16 118.92,79.77C121.76,58.07 110.94,39.2 89.65,29.71z"
android:fillColor="#028779" />
<path
android:pathData="M90.01,29.85C110.94,39.2 121.76,58.07 118.92,79.77C116.37,99.16 100.39,115.51 80.74,118.84C62.09,121.99 43.23,113.32 33.33,97.04C23.38,80.68 24.57,59.87 36.32,44.59C47.84,29.62 67.52,23.19 85.87,28.43C87.15,28.79 88.39,29.28 90.01,29.85M43.19,65.49C40.12,79.86 45.57,92.61 58.21,99.92C70.93,106.51 86.03,104.33 94.24,94.59C91.33,91.75 88.41,88.89 85.48,86.03C75.98,91.54 72.97,91.86 63.66,87.89C56.66,83.06 54.51,76.3 56.24,67.56C58.84,64.27 61.45,60.98 64.83,57.44C72.34,53.72 79.21,55.37 84.88,59.73C88.12,56.53 91.01,53.68 93.9,50.84C84.97,41.28 69.67,39.41 57.03,46.8C50.17,51.04 45.42,56.86 43.19,65.49z"
android:fillColor="#FAFBFB" />
<path
android:pathData="M57.69,46.56C69.67,39.41 84.97,41.28 93.9,50.84C91.01,53.68 88.12,56.53 84.88,59.73C79.21,55.37 72.34,53.72 64.29,57.22C61.73,53.52 59.71,50.04 57.69,46.56z"
android:fillColor="#09998A" />
<path
android:pathData="M64.09,88.31C72.97,91.86 75.98,91.54 85.48,86.03C88.41,88.89 91.33,91.75 94.24,94.59C86.03,104.33 70.93,106.51 58.14,99.37C60.08,95.31 62.09,91.81 64.09,88.31z"
android:fillColor="#E82566" />
<path
android:pathData="M63.87,88.1C62.09,91.81 60.08,95.31 57.88,99.14C45.57,92.61 40.12,79.86 43.78,65.34C48.19,66.19 52.01,67.18 55.83,68.16C54.51,76.3 56.66,83.06 63.87,88.1z"
android:fillColor="#FD9A08" />
<path
android:pathData="M56.03,67.86C52.01,67.18 48.19,66.19 44.01,65.04C45.42,56.86 50.17,51.04 57.36,46.68C59.71,50.04 61.73,53.52 63.9,57.34C61.45,60.98 58.84,64.27 56.03,67.86z"
android:fillColor="#CCDA3F" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
\n(使用位置信息服务)</string>
<string name="location_settings_dialog_message_details_start_paragraph">您的设备将需要:</string>
<string name="location_settings_dialog_message_location_services_gps_and_nlp">使用GPS、WLAN、移动网络和传感器</string>
<string name="location_settings_dialog_message_gls_consent">使用位置信息服务;在提供该服务的过程中,可能会定期收集位置数据,并以匿名方式使用这类数据,从而提高位置信息的精准度并改善基于地理位置的服务。</string>
<string name="location_settings_dialog_message_gls_consent">使用 microG 位置信息服务;在提供该服务的过程中,microG 可能会定期收集位置数据,并以匿名方式使用这类数据,从而提高位置信息的精准度并改善基于地理位置的服务。</string>
<string name="location_settings_dialog_message_details_end_paragraph">有关详细信息,请访问 位置信息设置。</string>
<string name="location_settings_dialog_btn_cancel">不用了</string>
<string name="location_settings_dialog_btn_sure">确定</string>
Expand Down

0 comments on commit 569f45a

Please sign in to comment.