-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Location: ask for permissions if not granted at time of request
- Loading branch information
Showing
10 changed files
with
150 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...es-location/core/src/main/kotlin/org/microg/gms/location/manager/AskPermissionActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.microg.gms.location.manager | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.os.Message | ||
import android.os.Messenger | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.app.ActivityCompat | ||
import androidx.core.os.bundleOf | ||
|
||
const val EXTRA_MESSENGER = "messenger" | ||
const val EXTRA_PERMISSIONS = "permissions" | ||
const val EXTRA_GRANT_RESULTS = "results" | ||
|
||
private const val REQUEST_CODE_PERMISSION = 120 | ||
|
||
class AskPermissionActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
val permissions = intent?.getStringArrayExtra(EXTRA_PERMISSIONS) ?: emptyArray() | ||
ActivityCompat.requestPermissions(this, permissions, REQUEST_CODE_PERMISSION) | ||
} | ||
|
||
private fun sendReply(code: Int = RESULT_OK, extras: Bundle = Bundle.EMPTY) { | ||
intent?.getParcelableExtra<Messenger>(EXTRA_MESSENGER)?.let { | ||
runCatching { | ||
it.send(Message.obtain().apply { | ||
what = code | ||
data = extras | ||
}) | ||
} | ||
} | ||
setResult(code, Intent().apply { putExtras(extras) }) | ||
} | ||
|
||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) { | ||
if (requestCode == REQUEST_CODE_PERMISSION) { | ||
sendReply(extras = bundleOf(EXTRA_GRANT_RESULTS to grantResults)) | ||
finish() | ||
} else { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters