一键清理——系统设置清除存储空间和清除缓存功能


通过系统设置中应用中的清空存储空间和清除缓存功能分析,来模拟一键清理相关的功能。
在这里插入图片描述

问题点

软件App 启动时候回崩溃、请求不了数据、一直加载、加载特别慢。 遇到过GMS Youtube 软件在平板产品上遇到过此问题。
部分产品,每次启动时候会有概率性崩溃,不稳定;加载不了视图。 比如 USBCamera 和 Camera 相关软件,链接设备节点的。

问题分析

在无解的情况下,清除应用缓存 或者 清空存储空间 发现解决了问题。

其它应用场景

应用退出时候清除自己一次,在某个app应用里面,控制其它app,进行清空缓存和数据。对于没有账户密码的产品 可以考虑这种方案。

修改源码

\vendor\mediatek\proprietary\packages\apps\MtkSettings\src\com\android\settings\applications\AppStorageSettings.java

日志分析

设置-应用-点击某个具体应用-应用信息-存储和缓存

可以看到如下日志

Switching to fragment com.android.settings.applications.AppStorageSettings

AppStorageSettings 源码分析

布局app_storage_settings.xml


<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:title="@string/storage_label">

    <com.android.settingslib.widget.ActionButtonsPreference
        android:key="header_view" />

    <Preference
        android:key="storage_used"
        android:title="@string/storage_used"
        android:summary="@string/storage_type_internal"
        android:selectable="false"
        android:layout="@layout/horizontal_preference" />

    <com.android.settingslib.widget.LayoutPreference
        android:key="change_storage_button"
        android:selectable="false"
        android:layout="@layout/single_button_panel" />

    <!-- 应用大小  用户数据 缓存 总计 -->
    <PreferenceCategory
        android:key="storage_category"
        android:title="@string/app_info_storage_title">

        <Preference
            android:key="app_size"
            android:title="@string/application_size_label"
            android:selectable="false"
            android:layout="@layout/horizontal_preference" />

        <Preference
            android:key="data_size"
            android:title="@string/data_size_label"
            android:selectable="false"
            android:layout="@layout/horizontal_preference" />

        <Preference
            android:key="cache_size"
            android:title="@string/cache_size_label"
            android:selectable="false"
            android:layout="@layout/horizontal_preference" />

        <Preference
            android:key="total_size"
            android:title="@string/total_size_label"
            android:selectable="false"
            android:layout="@layout/horizontal_preference" />

        <com.android.settings.applications.SpacePreference
            android:layout_height="8dp" />

    </PreferenceCategory>

    <PreferenceCategory
        android:key="uri_category"
        android:layout="@layout/preference_category_no_label"
        settings:allowDividerAbove="false"
        settings:allowDividerBelow="false">
        <com.android.settingslib.widget.LayoutPreference
            android:key="clear_uri_button"
            android:layout="@layout/single_button_panel"
            android:selectable="false" />
    </PreferenceCategory>

</PreferenceScreen>


根据经验:清除存储空间和清除缓存 按钮就是 header_view

<com.android.settingslib.widget.ActionButtonsPreference
        android:key="header_view" /><
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

野火少年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值