Skip to content

Commit bb96d4e

Browse files
fix crash in service
1 parent 547956d commit bb96d4e

17 files changed

+129
-50
lines changed

.idea/compiler.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ buildscript {
1818
// maven { url "https://github.com/LinXueyuanStdio/MLang/raw/main/dist/" }
1919
}
2020
dependencies {
21-
classpath 'com.android.tools.build:gradle:4.0.1'
21+
classpath 'com.android.tools.build:gradle:4.1.2'
2222
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2323
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
2424
// 最低支持 java7 的版本

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ org.gradle.jvmargs=-Xmx1536m
1212
# When configured, Gradle will run in incubating parallel mode.
1313
# This option should only be used with decoupled projects. More details, visit
1414
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
15-
android.nonTransitiveRClass=true
16-
android.enableAppCompileTimeRClass=true
15+
#android.nonTransitiveRClass=true
16+
#android.enableAppCompileTimeRClass=true
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Jul 17 18:49:33 CST 2020
1+
#Fri Mar 19 22:02:00 CST 2021
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

module-file/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apply from: "${project.rootDir}/gradle/library_header.gradle"
55
//}
66

77
android {
8-
// ndkVersion '21.3.6528147'
8+
ndkVersion '21.3.6528147'
99
defaultConfig {
1010
resValue 'string', 'app_version', rootProject.ext.android["versionName"]
1111
consumerProguardFiles 'proguard-rules.pro'

module-file/src/main/AndroidManifest.xml

+7-5
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,13 @@
258258
</intent-filter>
259259
</service>
260260

261-
<provider
262-
android:name="me.zhanghai.android.files.app.AppProvider"
263-
android:authorities="${applicationId}.files.app_provider"
264-
android:exported="false" />
265-
261+
<!-- <provider-->
262+
<!-- android:name="me.zhanghai.android.files.app.AppProvider"-->
263+
<!-- android:authorities="${applicationId}.files.app_provider"-->
264+
<!-- android:exported="false" />-->
265+
<meta-data
266+
android:name="com.timecat.module.files.GlobalConfiguration"
267+
android:value="ConfigModule" />
266268
<provider
267269
android:name="me.zhanghai.android.files.file.FileProvider"
268270
android:authorities="${applicationId}.files.file_provider"

module-file/src/main/java/com/timecat/module/files/FileContainerService.kt

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.timecat.module.files
33
import android.content.ActivityNotFoundException
44
import android.content.Context
55
import android.content.Intent
6+
import com.timecat.component.commonsdk.utils.override.LogUtil
67
import com.timecat.element.alert.ToastUtil
78
import com.timecat.identity.data.block.type.CONTAINER_BLOCK_MEDIA_MODULE_FILE
89
import com.timecat.identity.readonly.RouterHub
@@ -65,7 +66,9 @@ class FileContainerService : ContainerService {
6566
private fun loadForFileDir(context: Context, parentUuid: Path, homeService: HomeService, callback: ContainerService.LoadCallback) {
6667
GlobalScope.launch(Dispatchers.IO) {
6768
val fileList = try {
69+
LogUtil.se("start load files")
6870
parentUuid.newDirectoryStream().use { directoryStream ->
71+
LogUtil.se("open files stream")
6972
val fileList = mutableListOf<me.zhanghai.android.files.file.FileItem>()
7073
for (path in directoryStream) {
7174
try {
@@ -74,11 +77,15 @@ class FileContainerService : ContainerService {
7477
e.printStackTrace()
7578
} catch (e: IOException) {
7679
e.printStackTrace()
80+
} catch (e: Exception) {
81+
e.printStackTrace()
7782
}
7883
}
84+
LogUtil.se("load files success")
7985
fileList
8086
}
8187
} catch (e: Exception) {
88+
e.printStackTrace()
8289
withContext(Dispatchers.Main) {
8390
val stateful = homeService.statefulView()
8491
stateful?.showError(e.message) {
@@ -122,6 +129,7 @@ class FileContainerService : ContainerService {
122129
if (path.isLinuxPath || path.isDocumentPath) {
123130
val intent = path.fileProviderUri.createViewIntent(mimeType)
124131
.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
132+
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
125133
.apply {
126134
extraPath = path
127135
maybeAddImageViewerActivityExtras(this, path, fileItems, mimeType)
@@ -130,6 +138,7 @@ class FileContainerService : ContainerService {
130138
if (withChooser) {
131139
it.withChooser(
132140
OpenFileAsDialogActivity::class.createIntent()
141+
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
133142
.putArgs(OpenFileAsDialogFragment.Args(path))
134143
)
135144
} else {
@@ -168,6 +177,7 @@ class FileContainerService : ContainerService {
168177
if (position == -1) {
169178
return
170179
}
180+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
171181
ImageViewerActivity.putExtras(intent, paths, position)
172182
}
173183

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2017 JessYan
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.timecat.module.files;
17+
18+
import android.app.Application;
19+
import android.content.Context;
20+
21+
import com.jess.arms.base.delegate.AppLifecycles;
22+
import com.jess.arms.di.module.GlobalConfigModule;
23+
import com.jess.arms.integration.ConfigModule;
24+
25+
import java.util.List;
26+
27+
import androidx.annotation.Keep;
28+
import androidx.annotation.NonNull;
29+
import androidx.fragment.app.FragmentManager;
30+
import me.zhanghai.android.files.app.AppProviderKt;
31+
32+
/**
33+
* ================================================
34+
* 组件的全局配置信息在此配置, 需要将此实现类声明到 AndroidManifest 中
35+
* CommonSDK 中已有 {@link com.timecat.component.commonsdk.core.GlobalConfiguration} 配置有所有组件都可公用的配置信息
36+
* 这里用来配置一些组件自身私有的配置信息
37+
*
38+
* @see com.jess.arms.base.delegate.AppDelegate
39+
* @see com.jess.arms.integration.ManifestParser
40+
* @see <a href="https://github.com/JessYanCoding/ArmsComponent/wiki#3.3">ConfigModule wiki 官方文档</a>
41+
* Created by JessYan on 12/04/2017 17:25
42+
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
43+
* <a href="https://github.com/JessYanCoding">Follow me</a>
44+
* ================================================
45+
*/
46+
@Keep
47+
public final class GlobalConfiguration implements ConfigModule {
48+
49+
@Override
50+
public void applyOptions(Context context, GlobalConfigModule.Builder builder) {
51+
52+
}
53+
54+
@Override
55+
public void injectAppLifecycle(Context context, List<AppLifecycles> lifecycles) {
56+
// AppLifecycles 的所有方法都会在基类 Application 的对应的生命周期中被调用,所以在对应的方法中可以扩展一些自己需要的逻辑
57+
// 可以根据不同的逻辑添加多个实现类
58+
59+
lifecycles.add(new AppLifecycles() {
60+
@Override
61+
public void attachBaseContext(@NonNull Context base) {
62+
63+
}
64+
65+
@Override
66+
public void onCreate(@NonNull Application application) {
67+
AppProviderKt.initApplication(application);
68+
}
69+
70+
@Override
71+
public void onTerminate(@NonNull Application application) {
72+
73+
}
74+
});
75+
}
76+
77+
@Override
78+
public void injectActivityLifecycle(Context context, List<Application.ActivityLifecycleCallbacks> lifecycles) {
79+
80+
}
81+
82+
@Override
83+
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
84+
85+
}
86+
87+
}

module-file/src/main/java/com/timecat/module/files/item/DirCard.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DirCard(
3434
val listener: Listener
3535
) : BaseItem<DirCard.DirCardVH>(fileItem.path.userFriendlyString) {
3636
class DirCardVH(v: View, adapter: FlexibleAdapter<*>) : AbsCardVH(v, adapter) {
37-
var title: AppCompatTextView = v.findViewById(R.id.title)
37+
var title: TextView = v.findViewById(R.id.title)
3838
var mTimerState: TextView = v.findViewById(R.id.state)
3939
var more: ImageView = v.findViewById(R.id.more)
4040
var redDot: TextView = v.findViewById(R.id.red_dot_tv)

module-file/src/main/java/com/timecat/module/files/item/FileCard.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class FileCard(
3636
val listener: Listener
3737
) : BaseItem<FileCard.FileCardVH>(fileItem.path.userFriendlyString) {
3838
class FileCardVH(v: View, adapter: FlexibleAdapter<*>) : AbsCardVH(v, adapter) {
39-
var title: AppCompatTextView = v.findViewById(R.id.title)
39+
var title: TextView = v.findViewById(R.id.title)
4040
var mTimerState: TextView = v.findViewById(R.id.state)
4141
var more: ImageView = v.findViewById(R.id.more)
4242
var redDot: TextView = v.findViewById(R.id.red_dot_tv)

module-file/src/main/java/com/timecat/module/files/item/NavigationCard.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class NavigationCard(
3131
val listener: Listener
3232
) : BaseItem<NavigationCard.NavigationCardVH>(fileItem.path.userFriendlyString) {
3333
class NavigationCardVH(v: View, adapter: FlexibleAdapter<*>) : AbsCardVH(v, adapter) {
34-
var title: AppCompatTextView = v.findViewById(R.id.title)
34+
var title: TextView = v.findViewById(R.id.title)
3535
var mTimerState: TextView = v.findViewById(R.id.state)
3636
var more: ImageView = v.findViewById(R.id.more)
3737
var redDot: TextView = v.findViewById(R.id.red_dot_tv)

module-file/src/main/java/me/zhanghai/android/files/app/AppProvider.kt

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import android.net.Uri
1313

1414
lateinit var application: Application private set
1515

16+
fun initApplication(context: Application) {
17+
application = context
18+
appInitializers.forEach { it() }
19+
}
20+
1621
class AppProvider : ContentProvider() {
1722
override fun onCreate(): Boolean {
1823
application = context as Application

module-file/src/main/java/me/zhanghai/android/files/app/AppUpgrader.kt

-31
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,5 @@
55

66
package me.zhanghai.android.files.app
77

8-
import androidx.core.content.edit
9-
import me.zhanghai.android.files.BuildConfig
10-
11-
private const val KEY_VERSION_CODE = "key_version_code"
12-
13-
private const val VERSION_CODE_BELOW_1_1_0 = 17
14-
private const val VERSION_CODE_1_1_0 = 18
15-
private const val VERSION_CODE_LATEST = BuildConfig.VERSION_CODE
16-
17-
private var lastVersionCode: Int
18-
get() {
19-
if (defaultSharedPreferences.all.isEmpty()) {
20-
// This is a new install.
21-
lastVersionCode = VERSION_CODE_LATEST
22-
return VERSION_CODE_LATEST
23-
}
24-
return defaultSharedPreferences.getInt(KEY_VERSION_CODE, VERSION_CODE_BELOW_1_1_0)
25-
}
26-
set(value) {
27-
defaultSharedPreferences.edit { putInt(KEY_VERSION_CODE, value) }
28-
}
29-
308
fun upgradeApp() {
31-
upgradeAppFrom(lastVersionCode)
32-
lastVersionCode = VERSION_CODE_LATEST
33-
}
34-
35-
private fun upgradeAppFrom(lastVersionCode: Int) {
36-
if (lastVersionCode < VERSION_CODE_1_1_0) {
37-
upgradeAppTo1_1_0(lastVersionCode)
38-
}
39-
// Continue with new `if`s on lastVersionCode instead of `else if`.
409
}

module-file/src/main/java/me/zhanghai/android/files/app/SystemServices.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ import android.os.storage.StorageManager
1515
import android.view.inputmethod.InputMethodManager
1616
import androidx.core.app.NotificationManagerCompat
1717
import androidx.preference.PreferenceManager
18+
import com.timecat.module.files.GlobalConfiguration
1819
import me.zhanghai.android.files.compat.getSystemServiceCompat
1920
import me.zhanghai.android.files.compat.mainExecutorCompat
2021
import java.util.concurrent.Executor
2122

22-
val appClassLoader = AppProvider::class.java.classLoader
23+
val appClassLoader = GlobalConfiguration::class.java.classLoader
2324

2425
val contentResolver: ContentResolver by lazy { application.contentResolver }
2526

module-file/src/main/java/me/zhanghai/android/files/navigation/NavigationItem.kt

+5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ import android.graphics.drawable.Drawable
1111
import android.os.storage.StorageVolume
1212
import androidx.annotation.DrawableRes
1313
import androidx.annotation.StringRes
14+
import com.timecat.component.commonsdk.utils.override.LogUtil
1415
import java8.nio.file.Path
1516
import me.zhanghai.android.files.compat.getDrawableCompat
1617
import me.zhanghai.android.files.file.DocumentTreeUri
1718

1819
abstract class NavigationItem {
20+
init {
21+
LogUtil.se("init NavigationItem")
22+
23+
}
1924
abstract val id: Long
2025

2126
fun getIcon(context: Context): Drawable = context.getDrawableCompat(iconRes!!)

module-file/src/main/java/me/zhanghai/android/files/navigation/NavigationItems.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ val navigationFileItems: List<FileItem>
5959
add(PrimaryStorageVolumeRootItem(storageVolume))
6060
}
6161
}
62-
val treeUris = DocumentTreesLiveData.valueCompat.toMutableList()
62+
val treeUris = DocumentTreeUri.persistedUris.toMutableList()
6363
for (storageVolume in storageVolumes) {
6464
if (storageVolume.isPrimaryCompat) {
6565
continue
@@ -74,7 +74,7 @@ val navigationFileItems: List<FileItem>
7474
}
7575

7676
//standardDirectory
77-
val standardDirectoryItems = StandardDirectoriesLiveData.valueCompat
77+
val standardDirectoryItems = standardDirectories
7878
.filter { it.isEnabled }
7979
.map { StandardDirectoryItem(it) }
8080
if (standardDirectoryItems.isNotEmpty()) {

0 commit comments

Comments
 (0)