google上架合規2.0

1.APP又一次因為通訊錄問題被下架了

已經做到了這四點了
1.通訊錄的應用場景必須合適,使用時彈窗提示用戶我們拿通訊錄的用途
2.上傳之前必須能夠提示用戶要上傳通訊錄了,讓用戶能夠做出選擇
3.上傳不能太頻繁
4.隱私政策聲明
根據審核小組的發來的郵件,這次的理由是我們使用通訊錄的理由不夠充分,修改了彈窗和隱私申明相關文案再次提審就沒問題了。

2.關于Google強制把compileSdkVersion升級到30帶來的問題。

由于google在android 10進行了分區的操作,之前有權限直接操作非私有目錄下的文件已經不行了,當時使用的是臨時替代方案使用android:requestLegacyExternalStorage="true"。但是在compileSdkVersion升級到30的時候這個標簽會自動忽略。還好我們自己應用使用到操作的文件并不多,主要是一個第三方的sdk,包含拍照和選圖以及壓縮功能,由于作者已經很久沒有更新了,只能自己下完包一個個去改了。主要的問題:
1.應用創建文件使用外部存儲空間
2.應用操作外部文件。
解決辦法:
第一個問題主要是在一些緩存文件的地方放在了外部存儲目錄,后面就統一使用getExternalCacheDir創建目錄了
第二個問題主要是會在圖片的壓縮還是直接用的絕對路徑,這個時候需要拿到文件的Uri,然后將文件復制到我們自己的目錄下進行操作。附上我自己的代碼

public static File from(Context context, Uri uri) throws IOException {
        InputStream inputStream = context.getContentResolver().openInputStream(uri);
        String fileName = getFileName(context, uri);
        String[] splitName = splitFileName(fileName);
        File tempFile = File.createTempFile(splitName[0], splitName[1]);
        tempFile = rename(tempFile, fileName);
        tempFile.deleteOnExit();
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(tempFile);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        if (inputStream != null) {
            copy(inputStream, out);
            inputStream.close();
        }

        if (out != null) {
            out.close();
        }
        return tempFile;
    }

    private static String[] splitFileName(String fileName) {
        String name = fileName;
        String extension = "";
        int i = fileName.lastIndexOf(".");
        if (i != -1) {
            name = fileName.substring(0, i);
            extension = fileName.substring(i);
        }

        return new String[]{name, extension};
    }

    private static String getFileName(Context context, Uri uri) {
        String result = null;
        if (uri.getScheme().equals("content")) {
            Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
            try {
                if (cursor != null && cursor.moveToFirst()) {
                    result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
        }
        if (result == null) {
            result = uri.getPath();
            int cut = result.lastIndexOf(File.separator);
            if (cut != -1) {
                result = result.substring(cut + 1);
            }
        }
        return result;
    }

    private static File rename(File file, String newName) {
        File newFile = new File(file.getParent(), newName);
        if (!newFile.equals(file)) {
            if (newFile.exists() && newFile.delete()) {
                Log.d("FileUtil", "Delete old " + newName + " file");
            }
            if (file.renameTo(newFile)) {
                Log.d("FileUtil", "Rename file to " + newName);
            }
        }
        return newFile;
    }

    private static long copy(InputStream input, OutputStream output) throws IOException {
        long count = 0;
        int n;
        byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
        while (EOF != (n = input.read(buffer))) {
            output.write(buffer, 0, n);
            count += n;
        }
        return count;
    }

3.APP獲取應用Android列表的問題。

在需要加上android 11android:name="android.permission.QUERY_ALL_PACKAGES"android:name="android.permission.QUERY_ALL_PACKAGES"申明否者無法直接獲取應用的安裝列表了。并且google明確提出明年這個也會被限制。
解決辦法:
1.在google管理后臺去提交申請
2.拿到你想查詢的應用的包名放到你的androidManifest文件里,在Android11沒有權限的情況是可以查到的

4.Unencrypted traffic allowed on all domains

Configure your application's network security to allow unencrypted traffic across all domains. Eavesdroppers can take advantage of this to intercept the data your application sends.If such data is sensitive or could be used to identify a user,this could compromisse user privacy. It is best to allow only encrypted traffic by setting the cleartextTrafficPermitted flag to false,or by adding an encryption policy for specific domains.

由于本身是一個老的項目,本身還有訪問一些http外鏈,所以基本都是明文請求,google play上架為了數據的安全性要求統一使用cleartextTrafficPermitted為false.但是這導致了http鏈接無法訪問,但是你可以在networkSecurityConfig配置文件中配置你信任的CA 如

<?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
        <domain-config>
            <domain includeSubdomains="true">example.com</domain>
            <trust-anchors>
                <certificates src="@raw/my_ca"/>
            </trust-anchors>
        </domain-config>
    </network-security-config>
    

具體一些其他的配置可以參考Android網絡安全配置

5.Encryption is not secure

Your application uses insecure encryption.

google play給了一個鏈接針對不安全加密問題的解決方法
看了下項目中設計到加密的地方就一個 接口的全局加密,用的是aes的對稱加密,對比google play的文檔應該指出的是加密的密鑰太容易獲取了,可以使用 AndroidKeystore 存儲密鑰。由于用官方的方法要額外引用三個包,我就沒采用官方的方法,直接寫了一個jni編譯成so用來獲取加密的key,再次提審也沒有這個問題了。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容