.class public Landroidx/room/util/CopyLock; .super Ljava/lang/Object; .source "CopyLock.java" # annotations .annotation build Landroidx/annotation/RestrictTo; value = { .enum Landroidx/annotation/RestrictTo$Scope;->LIBRARY_GROUP_PREFIX:Landroidx/annotation/RestrictTo$Scope; } .end annotation # static fields .field private static final sThreadLocks:Ljava/util/Map; .annotation system Ldalvik/annotation/Signature; value = { "Ljava/util/Map<", "Ljava/lang/String;", "Ljava/util/concurrent/locks/Lock;", ">;" } .end annotation .end field # instance fields .field private final mCopyLockFile:Ljava/io/File; .field private final mFileLevelLock:Z .field private mLockChannel:Ljava/nio/channels/FileChannel; .field private final mThreadLock:Ljava/util/concurrent/locks/Lock; # direct methods .method public static constructor ()V .locals 1 new-instance v0, Ljava/util/HashMap; invoke-direct {v0}, Ljava/util/HashMap;->()V sput-object v0, Landroidx/room/util/CopyLock;->sThreadLocks:Ljava/util/Map; return-void .end method .method public constructor (Ljava/lang/String;Ljava/io/File;Z)V .locals 2 .param p1 # Ljava/lang/String; .annotation build Landroidx/annotation/NonNull; .end annotation .end param .param p2 # Ljava/io/File; .annotation build Landroidx/annotation/NonNull; .end annotation .end param invoke-direct {p0}, Ljava/lang/Object;->()V new-instance v0, Ljava/io/File; const-string v1, ".lck" invoke-static {p1, v1}, Lf/e/c/a/a;->r(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; move-result-object p1 invoke-direct {v0, p2, p1}, Ljava/io/File;->(Ljava/io/File;Ljava/lang/String;)V iput-object v0, p0, Landroidx/room/util/CopyLock;->mCopyLockFile:Ljava/io/File; invoke-virtual {v0}, Ljava/io/File;->getAbsolutePath()Ljava/lang/String; move-result-object p1 invoke-static {p1}, Landroidx/room/util/CopyLock;->getThreadLock(Ljava/lang/String;)Ljava/util/concurrent/locks/Lock; move-result-object p1 iput-object p1, p0, Landroidx/room/util/CopyLock;->mThreadLock:Ljava/util/concurrent/locks/Lock; iput-boolean p3, p0, Landroidx/room/util/CopyLock;->mFileLevelLock:Z return-void .end method .method private static getThreadLock(Ljava/lang/String;)Ljava/util/concurrent/locks/Lock; .locals 2 sget-object v0, Landroidx/room/util/CopyLock;->sThreadLocks:Ljava/util/Map; monitor-enter v0 :try_start_0 invoke-interface {v0, p0}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object; move-result-object v1 check-cast v1, Ljava/util/concurrent/locks/Lock; if-nez v1, :cond_0 new-instance v1, Ljava/util/concurrent/locks/ReentrantLock; invoke-direct {v1}, Ljava/util/concurrent/locks/ReentrantLock;->()V invoke-interface {v0, p0, v1}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; :cond_0 monitor-exit v0 return-object v1 :catchall_0 move-exception p0 monitor-exit v0 :try_end_0 .catchall {:try_start_0 .. :try_end_0} :catchall_0 throw p0 .end method # virtual methods .method public lock()V .locals 3 iget-object v0, p0, Landroidx/room/util/CopyLock;->mThreadLock:Ljava/util/concurrent/locks/Lock; invoke-interface {v0}, Ljava/util/concurrent/locks/Lock;->lock()V iget-boolean v0, p0, Landroidx/room/util/CopyLock;->mFileLevelLock:Z if-eqz v0, :cond_0 :try_start_0 new-instance v0, Ljava/io/FileOutputStream; iget-object v1, p0, Landroidx/room/util/CopyLock;->mCopyLockFile:Ljava/io/File; invoke-direct {v0, v1}, Ljava/io/FileOutputStream;->(Ljava/io/File;)V invoke-virtual {v0}, Ljava/io/FileOutputStream;->getChannel()Ljava/nio/channels/FileChannel; move-result-object v0 iput-object v0, p0, Landroidx/room/util/CopyLock;->mLockChannel:Ljava/nio/channels/FileChannel; invoke-virtual {v0}, Ljava/nio/channels/FileChannel;->lock()Ljava/nio/channels/FileLock; :try_end_0 .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0 goto :goto_0 :catch_0 move-exception v0 new-instance v1, Ljava/lang/IllegalStateException; const-string v2, "Unable to grab copy lock." invoke-direct {v1, v2, v0}, Ljava/lang/IllegalStateException;->(Ljava/lang/String;Ljava/lang/Throwable;)V throw v1 :cond_0 :goto_0 return-void .end method .method public unlock()V .locals 1 iget-object v0, p0, Landroidx/room/util/CopyLock;->mLockChannel:Ljava/nio/channels/FileChannel; if-eqz v0, :cond_0 :try_start_0 invoke-virtual {v0}, Ljava/nio/channels/FileChannel;->close()V :try_end_0 .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0 :catch_0 :cond_0 iget-object v0, p0, Landroidx/room/util/CopyLock;->mThreadLock:Ljava/util/concurrent/locks/Lock; invoke-interface {v0}, Ljava/util/concurrent/locks/Lock;->unlock()V return-void .end method