Skip to content

Commit

Permalink
把申请摄像头、录音权限放到吊起音视频通话页面时机,去按照申请最小权限的原则去掉申请存储日志的权限。
Browse files Browse the repository at this point in the history
Change-Id: I81f5e676e958ef2fa1e149abe5ca01edd3f6a659
  • Loading branch information
SundoggyNew committed Jan 17, 2022
1 parent 91ab8ac commit 339469b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.tencent.iot.explorer.link.kitlink.activity.rtcui.videocall;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
Expand All @@ -16,13 +18,20 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.Group;
import androidx.core.app.ActivityCompat;

//import com.blankj.utilcode.util.ToastUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.squareup.picasso.Picasso;
import com.tencent.iot.explorer.link.T;
import com.tencent.iot.explorer.link.core.utils.Utils;
import com.tencent.iot.explorer.link.customview.dialog.PermissionDialog;
import com.tencent.iot.explorer.link.kitlink.consts.CommonField;
import com.tencent.iot.explorer.link.rtc.R;
import com.tencent.iot.explorer.link.rtc.model.IntentParams;
import com.tencent.iot.explorer.link.rtc.model.RoomKey;
Expand Down Expand Up @@ -103,6 +112,10 @@ public class TRTCVideoCallActivity extends AppCompatActivity implements NetWorkS
private TimerTask enterRoomTask = null;
private NetWorkStateReceiver netWorkStateReceiver;

private PermissionDialog permissionDialog = null;
private boolean requestCameraPermission = false;
private boolean requestRecordAudioPermission = false;

/**
* 拨号的回调
*/
Expand Down Expand Up @@ -374,6 +387,78 @@ private void removeIsEnterRoom60secondsTask() {
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 102 || requestCode == 103 || requestCode == 104) {
permissionDialog.dismiss();
permissionDialog = null;
if (!requestCameraPermission || !requestRecordAudioPermission) {
checkAndRequestPermission();
} else {
boolean calling = initData();
initListener();
checkoutIsEnterRoom60seconds(calling, getString(R.string.trtccalling_customer_no_resp));
}
}
}

private void checkAndRequestPermission() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_DENIED && !requestCameraPermission) {
// 查看请求camera权限的时间是否大于48小时
String cameraJsonString = Utils.INSTANCE.getStringValueFromXml(this, CommonField.PERMISSION_CAMERA, CommonField.PERMISSION_CAMERA);
long lasttime = 0L;
if (cameraJsonString != null) {
JSONObject cameraJson = JSON.parseObject(cameraJsonString);
lasttime = cameraJson.getLong(CommonField.PERMISSION_CAMERA);
}
if (cameraJsonString != null && lasttime > 0 && System.currentTimeMillis() / 1000 - lasttime < 48 * 60 * 60) {
T.show(getString(com.tencent.iot.explorer.link.R.string.permission_of_camera_refuse));
return;
}
if (permissionDialog == null) {
permissionDialog = new PermissionDialog(this, com.tencent.iot.explorer.link.R.mipmap.permission_camera ,getString(com.tencent.iot.explorer.link.R.string.permission_camera_lips), getString(com.tencent.iot.explorer.link.R.string.permission_camera_trtc));
permissionDialog.show();
requestCameraPermission = true;
}
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 102);

// 记录请求camera权限的时间
JSONObject json = new JSONObject();
json.put(CommonField.PERMISSION_CAMERA, System.currentTimeMillis() / 1000);
Utils.INSTANCE.setXmlStringValue(this, CommonField.PERMISSION_CAMERA, CommonField.PERMISSION_CAMERA, json.toJSONString());
return;
}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_DENIED && !requestRecordAudioPermission) {
// 查看请求mic权限的时间是否大于48小时
String micJsonString = Utils.INSTANCE.getStringValueFromXml(this, CommonField.PERMISSION_MIC, CommonField.PERMISSION_MIC);
long lasttime = 0L;
if (micJsonString != null) {
JSONObject micJson = JSON.parseObject(micJsonString);
lasttime = micJson.getLong(CommonField.PERMISSION_MIC);
}
if (micJsonString != null && lasttime > 0 && System.currentTimeMillis() / 1000 - lasttime < 48 * 60 * 60) {
T.show(getString(com.tencent.iot.explorer.link.R.string.permission_of_camera_mic_refuse));
return;
}
if (permissionDialog == null) {
permissionDialog = new PermissionDialog(this, com.tencent.iot.explorer.link.R.mipmap.permission_mic ,getString(com.tencent.iot.explorer.link.R.string.permission_mic_lips), getString(com.tencent.iot.explorer.link.R.string.permission_camera_trtc));
permissionDialog.show();
requestRecordAudioPermission = true;
}
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, 103);

// 记录请求mic权限的时间
JSONObject json = new JSONObject();
json.put(CommonField.PERMISSION_MIC, System.currentTimeMillis() / 1000);
Utils.INSTANCE.setXmlStringValue(this, CommonField.PERMISSION_MIC, CommonField.PERMISSION_MIC, json.toJSONString());
return;
}
boolean calling = initData();
initListener();
checkoutIsEnterRoom60seconds(calling, getString(R.string.trtccalling_customer_no_resp));
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -439,9 +524,10 @@ public void userOffline(String deviceId) {
});

initView();
boolean calling = initData();
initListener();
checkoutIsEnterRoom60seconds(calling, getString(R.string.trtccalling_customer_no_resp));
checkAndRequestPermission();
// boolean calling = initData();
// initListener();
// checkoutIsEnterRoom60seconds(calling, getString(R.string.trtccalling_customer_no_resp));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ class HomeFragment : BaseFragment(), HomeFragmentView, MyCallback, PayloadMessag
private var roomList: ArrayList<RoomEntity> = ArrayList()
private var roomsAdapter: RoomsAdapter? = null
private var handler = Handler()
private var permissionDialog: PermissionDialog? = null
private var requestCameraPermission = false
private var requestStoragePermission = false
private var requestRecordAudioPermission = false
private var deviceListEnd = false
private var shareDeviceListEnd = false

Expand Down Expand Up @@ -619,91 +615,13 @@ class HomeFragment : BaseFragment(), HomeFragmentView, MyCallback, PayloadMessag
} else {
layout_no_dev_2_show.visibility = View.GONE
}
requestCameraPermission = false
requestRecordAudioPermission = false
requestStoragePermission = false

if (deviceListEnd) {
this.deviceListEnd = true
}
if (shareDeviceListEnd) {
this.shareDeviceListEnd = true
}
if (this.deviceListEnd && this.shareDeviceListEnd) {
requestPermission()
}
}

private fun requestPermission() {

if ((shareDevList.size > 0 || devList.size > 0) && permissionDialog == null) {
if (!checkPermissions(Manifest.permission.CAMERA) && !requestCameraPermission) {
// 查看请求camera权限的时间是否大于48小时
var cameraJsonString = Utils.getStringValueFromXml(T.getContext(), CommonField.PERMISSION_CAMERA, CommonField.PERMISSION_CAMERA)
var cameraJson: JSONObject? = JSONObject.parse(cameraJsonString) as JSONObject?
val lasttime = cameraJson?.getLong(CommonField.PERMISSION_CAMERA)
if (lasttime != null && lasttime > 0 && System.currentTimeMillis() / 1000 - lasttime < 48*60*60) {
requestCameraPermission = true
T.show(getString(R.string.permission_of_camera_refuse))
return
}
permissionDialog = PermissionDialog(App.activity, R.mipmap.permission_camera ,getString(R.string.permission_camera_lips), getString(R.string.permission_camera_trtc))
permissionDialog!!.show()
requestPermissions(arrayOf(Manifest.permission.CAMERA), 103)
requestCameraPermission = true

// 记录请求camera权限的时间
var json = JSONObject()
json.put(CommonField.PERMISSION_CAMERA, System.currentTimeMillis() / 1000)
Utils.setXmlStringValue(T.getContext(), CommonField.PERMISSION_CAMERA, CommonField.PERMISSION_CAMERA, json.toJSONString())
return
}
requestCameraPermission = true
if (!checkPermissions(Manifest.permission.RECORD_AUDIO) && !requestRecordAudioPermission) {
// 查看请求mic权限的时间是否大于48小时
var micJsonString = Utils.getStringValueFromXml(T.getContext(), CommonField.PERMISSION_MIC, CommonField.PERMISSION_MIC)
var micJson: JSONObject? = JSONObject.parse(micJsonString) as JSONObject?
val lasttime = micJson?.getLong(CommonField.PERMISSION_MIC)
if (lasttime != null && lasttime > 0 && System.currentTimeMillis() / 1000 - lasttime < 48*60*60) {
requestRecordAudioPermission = true
T.show(getString(R.string.permission_of_camera_mic_refuse))
return
}
permissionDialog = PermissionDialog(App.activity, R.mipmap.permission_mic ,getString(R.string.permission_mic_lips), getString(R.string.permission_camera_trtc))
permissionDialog!!.show()
requestPermissions(arrayOf(Manifest.permission.RECORD_AUDIO), 104)
requestRecordAudioPermission = true

// 记录请求mic权限的时间
var json = JSONObject()
json.put(CommonField.PERMISSION_MIC, System.currentTimeMillis() / 1000)
Utils.setXmlStringValue(T.getContext(), CommonField.PERMISSION_MIC, CommonField.PERMISSION_MIC, json.toJSONString())
return
}
requestRecordAudioPermission = true
if ((!checkPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE) || !checkPermissions(Manifest.permission.READ_EXTERNAL_STORAGE)) && !requestStoragePermission) {
// 查看请求storage权限的时间是否大于48小时
var storageJsonString = Utils.getStringValueFromXml(T.getContext(), CommonField.PERMISSION_STORAGE, CommonField.PERMISSION_STORAGE)
var storageJson: JSONObject? = JSONObject.parse(storageJsonString) as JSONObject?
val lasttime = storageJson?.getLong(CommonField.PERMISSION_STORAGE)
if (lasttime != null && lasttime > 0 && System.currentTimeMillis() / 1000 - lasttime < 48*60*60) {
requestStoragePermission = true
T.show(getString(R.string.permission_of_camera_mic_refuse))
return
}
permissionDialog = PermissionDialog(App.activity, R.mipmap.permission_album ,getString(R.string.permission_storage_lips), getString(R.string.permission_storage))
permissionDialog!!.show()
requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE), 105)
requestStoragePermission = true

// 记录请求storage权限的时间
var json = JSONObject()
json.put(CommonField.PERMISSION_STORAGE, System.currentTimeMillis() / 1000)
Utils.setXmlStringValue(T.getContext(), CommonField.PERMISSION_STORAGE, CommonField.PERMISSION_STORAGE, json.toJSONString())
return
}
requestStoragePermission = true
}
}

private fun checkPermissions(permission: String): Boolean {
Expand All @@ -715,21 +633,6 @@ class HomeFragment : BaseFragment(), HomeFragmentView, MyCallback, PayloadMessag
return true
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (permissions.contains(Manifest.permission.CAMERA) || permissions.contains(Manifest.permission.RECORD_AUDIO) || permissions.contains(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
permissionDialog?.dismiss()
permissionDialog = null
if (!requestCameraPermission || !requestRecordAudioPermission || !requestStoragePermission) {
requestPermission()
}
}
}

override fun showDeviceOnline() {
for (i in 0 until devList.size) {
if (i >= presenter.getIModel(this).deviceList.size) {
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-en-rUS/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,6 @@
<string name="permission_storage_camera_lips">· Storage</string>
<string name="permission_album_avatar">In order to facilitate you to choose a local picture to change your profile picture, Tencent LLink needs to obtain the following permissions:</string>
<string name="permission_album_lips">· Storage (photo album)</string>
<string name="permission_storage">In order to use the real-time voice/video call function of the device and record the operation log, Tencent LLink needs to obtain the following permissions:</string>
<string name="permission_storage_lips">· Storage (log)</string>
<string name="permission_location_ssid">In order to facilitate the automatic acquisition of the WiFi name of the current mobile phone connection when configuring the network for the device, and send the WiFi information to the device to complete the network configuration, Tencent LLink needs to obtain the following permissions:</string>
<string name="permission_location_ssid_map">In order to provide you with precise positioning service, it is convenient to set the home location to obtain weather service, Tencent LLink needs to obtain the following permissions:</string>
<string name="permission_location_ssid_ble">In order to provide you with precise positioning service, it is convenient to search and control Bluetooth devices, Tencent LLink needs to obtain the following permissions:</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,6 @@
<string name="permission_storage_camera_lips">· 存储</string>
<string name="permission_album_avatar">为了便于您可选择本地图片以更换头像,因此腾讯连连需获取以下权限:</string>
<string name="permission_album_lips">· 存储(相册)</string>
<string name="permission_storage">为了使用设备的实时语音/视频通话功能,记录运行日志,因此腾讯连连需获取以下权限:</string>
<string name="permission_storage_lips">· 存储(日志)</string>
<string name="permission_location_ssid">为了便于给设备配网时,自动获取当前手机连接的WiFi名称,向设备发送WiFi信息完成配网,因此腾讯连连需获取以下权限:</string>
<string name="permission_location_ssid_map">为了给您提供精确定位服务,便于设置家庭位置获取天气服务,因此腾讯连连需获取以下权限:</string>
<string name="permission_location_ssid_ble">为了给您提供精确定位服务,便于搜索操控蓝牙设备,因此腾讯连连需获取以下权限:</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,6 @@
<string name="permission_storage_camera_lips">· 存储</string>
<string name="permission_album_avatar">为了便于您可选择本地图片以更换头像,因此腾讯连连需获取以下权限:</string>
<string name="permission_album_lips">· 存储(相册)</string>
<string name="permission_storage">为了使用设备的实时语音/视频通话功能,记录运行日志,因此腾讯连连需获取以下权限:</string>
<string name="permission_storage_lips">· 存储(日志)</string>
<string name="permission_location_ssid">为了便于给设备配网时,自动获取当前手机连接的WiFi名称,向设备发送WiFi信息完成配网,因此腾讯连连需获取以下权限:</string>
<string name="permission_location_ssid_map">为了给您提供精确定位服务,便于设置家庭位置获取天气服务,因此腾讯连连需获取以下权限:</string>
<string name="permission_location_ssid_ble">为了给您提供精确定位服务,便于搜索操控蓝牙设备,因此腾讯连连需获取以下权限:</string>
Expand Down

0 comments on commit 339469b

Please sign in to comment.