Loading core/java/android/view/textclassifier/TextClassifierImpl.java +21 −13 Original line number Diff line number Diff line Loading @@ -84,12 +84,17 @@ public final class TextClassifierImpl implements TextClassifier { private final GenerateLinksLogger mGenerateLinksLogger; private final Object mLock = new Object(); @GuardedBy("mLock") // Do not access outside this lock. private ModelFileManager.ModelFile mAnnotatorModelInUse; @GuardedBy("mLock") // Do not access outside this lock. private AnnotatorModel mAnnotatorImpl; @GuardedBy("mLock") // Do not access outside this lock. private ModelFileManager.ModelFile mLangIdModelInUse; @GuardedBy("mLock") // Do not access outside this lock. private LangIdModel mLangIdImpl; @GuardedBy("mLock") // Do not access outside this lock. private ModelFileManager.ModelFile mActionModelInUse; @GuardedBy("mLock") // Do not access outside this lock. Loading Loading @@ -515,17 +520,19 @@ public final class TextClassifierImpl implements TextClassifier { private LangIdModel getLangIdImpl() throws FileNotFoundException { synchronized (mLock) { if (mLangIdImpl == null) { final ModelFileManager.ModelFile bestModel = mLangIdModelFileManager.findBestModelFile(null); if (bestModel == null) { throw new FileNotFoundException("No LangID model is found"); } if (mLangIdImpl == null || !Objects.equals(mLangIdModelInUse, bestModel)) { Log.d(DEFAULT_LOG_TAG, "Loading " + bestModel); final ParcelFileDescriptor pfd = ParcelFileDescriptor.open( new File(bestModel.getPath()), ParcelFileDescriptor.MODE_READ_ONLY); try { if (pfd != null) { mLangIdImpl = new LangIdModel(pfd.getFd()); mLangIdModelInUse = bestModel; } } finally { maybeCloseAndLogError(pfd); Loading @@ -538,13 +545,14 @@ public final class TextClassifierImpl implements TextClassifier { @Nullable private ActionsSuggestionsModel getActionsImpl() throws FileNotFoundException { synchronized (mLock) { if (mActionsImpl == null) { // TODO: Use LangID to determine the locale we should use here? final ModelFileManager.ModelFile bestModel = mActionsModelFileManager.findBestModelFile(LocaleList.getDefault()); if (bestModel == null) { return null; } if (mActionsImpl == null || !Objects.equals(mActionModelInUse, bestModel)) { Log.d(DEFAULT_LOG_TAG, "Loading " + bestModel); final ParcelFileDescriptor pfd = ParcelFileDescriptor.open( new File(bestModel.getPath()), ParcelFileDescriptor.MODE_READ_ONLY); try { Loading Loading
core/java/android/view/textclassifier/TextClassifierImpl.java +21 −13 Original line number Diff line number Diff line Loading @@ -84,12 +84,17 @@ public final class TextClassifierImpl implements TextClassifier { private final GenerateLinksLogger mGenerateLinksLogger; private final Object mLock = new Object(); @GuardedBy("mLock") // Do not access outside this lock. private ModelFileManager.ModelFile mAnnotatorModelInUse; @GuardedBy("mLock") // Do not access outside this lock. private AnnotatorModel mAnnotatorImpl; @GuardedBy("mLock") // Do not access outside this lock. private ModelFileManager.ModelFile mLangIdModelInUse; @GuardedBy("mLock") // Do not access outside this lock. private LangIdModel mLangIdImpl; @GuardedBy("mLock") // Do not access outside this lock. private ModelFileManager.ModelFile mActionModelInUse; @GuardedBy("mLock") // Do not access outside this lock. Loading Loading @@ -515,17 +520,19 @@ public final class TextClassifierImpl implements TextClassifier { private LangIdModel getLangIdImpl() throws FileNotFoundException { synchronized (mLock) { if (mLangIdImpl == null) { final ModelFileManager.ModelFile bestModel = mLangIdModelFileManager.findBestModelFile(null); if (bestModel == null) { throw new FileNotFoundException("No LangID model is found"); } if (mLangIdImpl == null || !Objects.equals(mLangIdModelInUse, bestModel)) { Log.d(DEFAULT_LOG_TAG, "Loading " + bestModel); final ParcelFileDescriptor pfd = ParcelFileDescriptor.open( new File(bestModel.getPath()), ParcelFileDescriptor.MODE_READ_ONLY); try { if (pfd != null) { mLangIdImpl = new LangIdModel(pfd.getFd()); mLangIdModelInUse = bestModel; } } finally { maybeCloseAndLogError(pfd); Loading @@ -538,13 +545,14 @@ public final class TextClassifierImpl implements TextClassifier { @Nullable private ActionsSuggestionsModel getActionsImpl() throws FileNotFoundException { synchronized (mLock) { if (mActionsImpl == null) { // TODO: Use LangID to determine the locale we should use here? final ModelFileManager.ModelFile bestModel = mActionsModelFileManager.findBestModelFile(LocaleList.getDefault()); if (bestModel == null) { return null; } if (mActionsImpl == null || !Objects.equals(mActionModelInUse, bestModel)) { Log.d(DEFAULT_LOG_TAG, "Loading " + bestModel); final ParcelFileDescriptor pfd = ParcelFileDescriptor.open( new File(bestModel.getPath()), ParcelFileDescriptor.MODE_READ_ONLY); try { Loading